Skip to content
Tags

,

Enumerator

April 7, 2011
ruby-1.9.2-p0 :024 > a = [1, 2, "cat"]

=> [1, 2, "cat"]

ruby-1.9.2-p0 :025 > enum_a = a.to_enum

=> #<Enumerator: [1, 2, "cat"]:each>

ruby-1.9.2-p0 :026 > enum_a.next

=> 1

ruby-1.9.2-p0 :027 > enum_a.next

=> 2

ruby-1.9.2-p0 :028 > enum_a.next

=> "cat"

ruby-1.9.2-p0 :029 > enum_a.next

StopIteration: iteration reached an end

from (irb):29:in `next'

from (irb):29

from /Users/gaganawhad/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start'

from /Users/gaganawhad/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start'

from /Users/gaganawhad/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>'

from script/rails:6:in `require'

from script/rails:6:in `<main>'

ruby-1.9.2-p0 :030 > enum_a = a.enum_for

=> #<Enumerator: [1, 2, "cat"]:each>

ruby-1.9.2-p0 :031 > enum_a.next

=> 1

ruby-1.9.2-p0 :032 > enum_a.next

=> 2

ruby-1.9.2-p0 :033 > enum_a.next

=> "cat"

ruby-1.9.2-p0 :035 > enum_a = a.each

=> #<Enumerator: [1, 2, "cat"]:each>

ruby-1.9.2-p0 :036 > enum_a.next

=> 1

ruby-1.9.2-p0 :037 > enum_a.next

=> 2

ruby-1.9.2-p0 :038 > enum_a.next

=> "cat"
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: