Any syntax to see the methods provided by the module Enumerable?

Enumerable module, a module that supplies about 20 useful counting- and
iteration-related
methods, including collect, detect, find, find_all, include?, max, min,
select, sort, and to_a.

What is the syntax to view these methods?
For example, if I want to know the methods available for the String
class, I could type “I love Ruby”.methods

I’ve tried Enumerable.methods , couldn’t find “collect, detect, find,
find_all, include?, max, min, select, sort, and to_a” in there.

I’m using Ruby 1.9.2

Thanks a lot guys!

Kaye Ng wrote in post #1003182:

Enumerable module, a module that supplies about 20 useful counting- and
iteration-related
methods, including collect, detect, find, find_all, include?, max, min,
select, sort, and to_a.

What is the syntax to view these methods?

Enumerable.instance_methods
=> [“count”, “partition”, “max_by”, “member?”, “cycle”, “entries”,
“collect”, “min”, “take”, “find_index”, “one?”, “each_with_index”,
“enum_slice”, “grep”, “reduce”, “min_by”, “drop_while”, “reject”, “zip”,
“to_a”, “detect”, “first”, “any?”, “each_slice”, “sort_by”, “inject”,
“minmax”, “drop”, “select”, “include?”, “reverse_each”, “enum_cons”,
“find”, “group_by”, “all?”, “minmax_by”, “sort”, “map”, “max”,
“take_while”, “find_all”, “none?”, “enum_with_index”, “each_cons”]

I’ve tried Enumerable.methods , couldn’t find “collect, detect, find,
find_all, include?, max, min, select, sort, and to_a” in there.

It would work if you did this on an object which included Enumerable,
rather than on the module Enumerable itself. e.g.

[].methods

or:

foo = Object.new
foo.extend Enumerable
foo.methods

However that would of course show you all the methods in that object,
Enumerable and others.

Kaye Ng wrote in post #1003182:

I’ve tried Enumerable.methods , couldn’t find “collect, detect, find,
find_all, include?, max, min, select, sort, and to_a” in there.

Enumberable.methods asks the question, “What methods does the object
Enumerable respond to?” In other words, find all the methods that work
in place of a_meth here:

Enumerable.a_meth

If you want to know what methods the instances of the Enumberable
class respond to, then you can say:

Enumerable.instance_methods

And to make things easy to view:

p Enumerable.instance_methods.sort

From the command line:

$ ri Enumerable

From the command-line, start irb with the following options:

$ irb --readline -r irb/completion

Then, at the irb-prompt, type Enumerator, dot, and twice tab. Then irb
spits out all available methods.

irb(main):001:0> Enumerator.

                                   Enumerator.instance_variables

Enumerator.id Enumerator.is_a?
Enumerator.send Enumerator.kind_of?
Enumerator.allocate Enumerator.method
Enumerator.ancestors Enumerator.method_defined?
Enumerator.autoload Enumerator.methods
Enumerator.autoload? Enumerator.module_eval
Enumerator.class Enumerator.module_exec
Enumerator.class_eval Enumerator.name
Enumerator.class_exec Enumerator.new
Enumerator.class_variable_defined? Enumerator.nil?
Enumerator.class_variable_get Enumerator.object_id
Enumerator.class_variable_set Enumerator.private_class_method
Enumerator.class_variables
Enumerator.private_instance_methods
Enumerator.clone
Enumerator.private_method_defined?
Enumerator.const_defined? Enumerator.private_methods
Enumerator.const_get
Enumerator.protected_instance_methods
Enumerator.const_missing
Enumerator.protected_method_defined?
Enumerator.const_set Enumerator.protected_methods
Enumerator.constants Enumerator.public_class_method
Enumerator.define_singleton_method Enumerator.public_instance_method
Enumerator.display
Enumerator.public_instance_methods
Enumerator.dup Enumerator.public_method
Enumerator.enum_for Enumerator.public_method_defined?
Enumerator.eql? Enumerator.public_methods
Enumerator.equal? Enumerator.public_send
Enumerator.extend Enumerator.remove_class_variable
Enumerator.freeze Enumerator.respond_to?
Enumerator.frozen? Enumerator.respond_to_missing?
Enumerator.hash Enumerator.send
Enumerator.include? Enumerator.singleton_class
Enumerator.included_modules Enumerator.singleton_methods
Enumerator.initialize_clone Enumerator.superclass
Enumerator.initialize_dup Enumerator.taint
Enumerator.inspect Enumerator.tainted?
Enumerator.instance_eval Enumerator.tap
Enumerator.instance_exec Enumerator.to_enum
Enumerator.instance_method Enumerator.to_s
Enumerator.instance_methods Enumerator.trust
Enumerator.instance_of? Enumerator.untaint
Enumerator.instance_variable_defined? Enumerator.untrust
Enumerator.instance_variable_get Enumerator.untrusted?
Enumerator.instance_variable_set

Agent M. wrote in post #1004051:

Then, at the irb-prompt, type Enumerator, dot, and twice tab. Then irb
spits out all available methods.

Except that the OP wanted instance methods of Enumerable, not class
methods of Enumerator.

Consider the difference between:

String.

and

“”.

If you’re looking for String#length or String#sub, the first one won’t
show you them, but the second will.