From: RichardSchollar on
I have only just started using Ruby (and am a total noob, in case this
wasn't obvious ;-)) and was wondering if I type the following into irb
(for instance) I don't see the "include" method listed:

Array.methods

Nor do I see the "each" method listed so I assume this is by design
rather than being an omission.

Would someone be so kind as to enlighten me why this is the case?

Many thanks.

Richard
From: Brian Candler on
RichardSchollar wrote:
> I have only just started using Ruby (and am a total noob, in case this
> wasn't obvious ;-)) and was wondering if I type the following into irb
> (for instance) I don't see the "include" method listed:
>
> Array.methods

You want: Array.instance_methods

(that is: not methods of the class Array object itself, but methods of
objects which are instances of class Array)
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Brian Candler wrote:
> RichardSchollar wrote:
>> I have only just started using Ruby (and am a total noob, in case this
>> wasn't obvious ;-)) and was wondering if I type the following into irb
>> (for instance) I don't see the "include" method listed:
>>
>> Array.methods
>
> You want: Array.instance_methods
>
> (that is: not methods of the class Array object itself, but methods of
> objects which are instances of class Array)

Or alternatively you could do: Array.new.methods
to create an instance, and then see what methods it has.

irb(main):001:0> Array.new.methods.grep(/inject/)
=> ["inject"]
--
Posted via http://www.ruby-forum.com/.

From: Robert Dober on
On Sun, Jun 6, 2010 at 9:53 PM, Brian Candler <b.candler(a)pobox.com> wrote:

> irb(main):001:0> Array.new.methods.grep(/inject/)
> => ["inject"]
In irb I would use [] instead of Array.new in that case ;)
Cheers
R.

From: Rein Henrichs on
In addition to the previously mentioned difference between #methods and
#instance_methods, #inject is actually a method on the Enumerable
module, which is mixed into Array (and other classes that have #each).
The Enumerable module is full of methods that can be used on "things
that can enumerate themselves", like Arrays, Hashes and Sets.

--
Rein Henrichs
http://puppetlabs.com
http://reinh.com