7stud2
(7stud --)
2 February 2013 12:27
1
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?
--
Posted via http://www.ruby-forum.com/ .
stomar
(stomar)
2 February 2013 15:26
2
"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.
···
Am 02.02.2013 13:27, schrieb Arup Rakshit:
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?
--
<https://github.com/stomar/> ;
7stud2
(7stud --)
2 February 2013 15:40
3
unknown wrote in post #1094896:
···
Am 02.02.2013 13:27, schrieb Arup Rakshit:
====================================================
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?
--
Posted via http://www.ruby-forum.com/\ .