Last active
August 29, 2015 13:57
-
-
Save alexhawkins/12af5b64c5cd7f8b1018 to your computer and use it in GitHub Desktop.
Confused about when to use self again? This works the same without self. Also why use & instead :&
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 new_map | |
new_array = [] | |
self.each do |item| | |
new_array << yield(item) | |
end | |
new_array | |
end | |
def new_map!(&block) | |
self.replace(.self.new_map(&block)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Confused about when to use self again? This works the same without self. Also why use & instead :&