Hi --
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.
Although a surprising (to me) number of Enumerable's instance methods
are overridden in Array:
irb(main):008:0> (Array.instance_methods(false) &
Enumerable.instance_methods).sort
=> ["collect", "count", "cycle", "drop", "drop_while", "find_index",
"first", "include?", "map", "reject", "reverse_each", "select",
"sort", "take", "take_while", "to_a", "zip"]
(That's 1.8.7 but the list is the same in 1.9.1.)
David
···
On Mon, 7 Jun 2010, Rein Henrichs wrote:
--
David A. Black, Senior Developer, Cyrus Innovation Inc.
THE Ruby training with Black/Brown/McAnally
COMPLEAT Coming to Chicago area, June 18-19, 2010!
RUBYIST http://www.compleatrubyist.com