In ruby, what kind of object is (x..y)? An enumerator?

65 views Asked by At

Ive seen this form crop up, for example, as:

 (x..y).map { |i| 2*i }.inject(:+)

so it seems to be creating an enumerator? But i can't find a definition of the syntax in ruby-docs and it's a hard string to google!

Thanks for any help!

3

There are 3 answers

0
three On BEST ANSWER

Thse are Ranges which are described here: http://www.tutorialspoint.com/ruby/ruby_ranges.htm

Or in the official docs they can be found here: http://www.ruby-doc.org/core-2.1.5/Range.html

0
sebkkom On
irb(main):001:0> (1..3).class
=> Range

And while we are on documentation and stuff, let me suggest omniref

2
Kirill Platonov On
[9] pry(main)> (1..3).class
=> Range
[10] pry(main)> (1..3).class.ancestors
=> [Range, Enumerable, Object, PP::ObjectMixin, Kernel, BasicObject]