Created
February 8, 2015 18:10
-
-
Save compwron/b1b7380bf61d8d4f2814 to your computer and use it in GitHub Desktop.
modify array in place
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def square! | |
self.map! {|i| i ** 2} | |
end | |
end | |
a = [1, 2, 3] | |
a.square! | |
if a == [1, 4, 9] | |
puts "yay!" | |
else | |
puts "try again" | |
puts a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment