Skip to content

Instantly share code, notes, and snippets.

@mikelikesbikes
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikelikesbikes/8809504 to your computer and use it in GitHub Desktop.
Save mikelikesbikes/8809504 to your computer and use it in GitHub Desktop.
What'chu doin' Ruby?
$ ruby -e "a = (0..5).to_a; c = a.map do |x| x*2; end; p c.class"
Array
$ ruby -e "a = (0..5).to_a; c = a.map { |x| x*2; }; p c.class"
Array
$ ruby -e "a = (0..5).to_a; p a.map do |x| x*2; end"
#<Enumerator: [0, 1, 2, 3, 4, 5]:map>
$ ruby -e "a = (0..5).to_a; p a.map { |x| x*2; }"
[0, 2, 4, 6, 8, 10]
@ryanbriones
Copy link

I would assume this:

$ ruby -e "a = (0..5).to_a; p a.map do |x| x*2; end"

is being interpreted as this:

$ ruby -e "a = (0..5).to_a; p(a.map); do |x| x*2; end"

@ryanbriones
Copy link

Or something like that... (that code doesn't work apparently)

@mikelikesbikes
Copy link
Author

@JoshCheek THANKS!

@ryanbriones see Josh's example... it's being interpreted like this:
$ ruby -e "a = (0..5).to_a; p(a.map) do |x| x*2; end"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment