Confusion with Enum#with_index

I was playing to understand the method “Enum#with_index” with the below
code:

===================================================
irb(main):024:0> xs = [‘a’, ‘b’, ‘c’]
=> [“a”, “b”, “c”]
irb(main):025:0> xs.to_enum.with_index(2)
=> #<Enumerator: #<Enumerator: [“a”, “b”, “c”]:each>:with_index(2)>

====================================================

irb(main):014:0> to_three = Enumerator.new do |y|
irb(main):015:1* 3.times do |x|
irb(main):016:2* y<<x
irb(main):017:2> end
irb(main):018:1> end
=> #<Enumerator: #Enumerator::Generator:0x2193ca8:each>
irb(main):027:0> to_three.with_index(2)
=> #<Enumerator: #<Enumerator:
#Enumerator::Generator:0x2193ca8:each>:with_ind
ex(2)>

====================================================

Couldn’t understand the output of “to_three.with_index(2)” .

Could anyone help me?

Am 02.02.2013 13:27, schrieb Arup R.:

====================================================

Couldn’t understand the output of “to_three.with_index(2)” .

Could anyone help me?

“Couldn’t understand…” is not a particularly clear way to
ask a question.

What did you expect? What puzzled you?

The “output” is only the string representation of the enumerator
object that you created. But you haven’t “done” anything with it.

unknown wrote in post #1094896:

Am 02.02.2013 13:27, schrieb Arup R.:

====================================================

Couldn’t understand the output of “to_three.with_index(2)” .

Could anyone help me?

#Enumerator::Generator:0x2193ca8:each>
irb(main):027:0> to_three.with_index(2) <— this output is making
confused me. What it refers to? What is it holding?

Am 02.02.2013 16:40, schrieb Arup R.:

#Enumerator::Generator:0x2193ca8:each>
irb(main):027:0> to_three.with_index(2) <— this output is making
confused me. What it refers to? What is it holding?

??? That’s your input.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs