Skip to content

Instantly share code, notes, and snippets.

@samueljseay
Created November 21, 2012 03:53
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 samueljseay/4122912 to your computer and use it in GitHub Desktop.
Save samueljseay/4122912 to your computer and use it in GitHub Desktop.
tutorial error
1.9.3p327 :013 > pets = %w(rex nibbles fred)
=> ["rex", "nibbles", "fred"]
1.9.3p327 :014 > puts pets.map do |pet|
1.9.3p327 :015 > pet.upcase
1.9.3p327 :016?> end
#<Enumerator:0x007f9b4d02a4f0>
=> nil
1.9.3p327 :017 > puts pets.map(&:upcase)
REX
NIBBLES
FRED
=> nil
@schneems
Copy link

1.9.3p194 :002 > %w(foo bar baz)
=> ["foo", "bar", "baz"]
1.9.3p194 :003 > array = %w(foo bar baz)
=> ["foo", "bar", "baz"]
1.9.3p194 :004 > result = array.map do |x|
1.9.3p194 :005 > x.upcase
1.9.3p194 :006?> end
=> ["FOO", "BAR", "BAZ"]
1.9.3p194 :007 >
1.9.3p194 :008 >
1.9.3p194 :009 > puts result.inspect

@samueljseay
Copy link
Author

you didn't do this:

puts pets.map do |pet|
pet.upcase
end

the 2 are equivalent but result for some reason is different...

@parndt
Copy link

parndt commented Nov 21, 2012

@schneems yep, @samueljseay is right.

@parndt
Copy link

parndt commented Nov 21, 2012

@schneems on the video I think you didn't want "puts" in there.

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