Skip to content

Instantly share code, notes, and snippets.

@supermomonga
Created January 19, 2015 08:07
Show Gist options
  • Save supermomonga/8248f7640929a65c9361 to your computer and use it in GitHub Desktop.
Save supermomonga/8248f7640929a65c9361 to your computer and use it in GitHub Desktop.
def hr
puts '-' * 50
end
a = [10,100,1000].each_with_object(2)
b = [10,100,1000].map{|x|[x,2]}.map
p a.class
p b.class
#=> Enumerator
#=> Enumerator
hr
p a.inspect
p b.inspect
#=> "#<Enumerator: [10, 100, 1000]:each_with_object(2)>"
#=> "#<Enumerator: [[10, 2], [100, 2], [1000, 2]]:map>"
hr
p [a.first, a.first.class]
p [b.first, b.first.class]
#=> [[10, 2], Array]
#=> [[10, 2], Array]
hr
p a.to_a
p b.to_a
#=> [[10, 2], [100, 2], [1000, 2]]
#=> [[10, 2], [100, 2], [1000, 2]]
hr
p a.map(&:to_s)
p b.map(&:to_s)
#=> ["1010", "1100100", "1111101000"]
#=> ["[10, 2]", "[100, 2]", "[1000, 2]"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment