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?
on 2013-02-02 13:26
on 2013-02-02 16:26
Am 02.02.2013 13:27, schrieb Arup Rakshit: > > > ==================================================== > > 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.
on 2013-02-02 16:39
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?
on 2013-02-02 17:14
Am 02.02.2013 16:40, schrieb Arup Rakshit: > > #<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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.