Skip to content

Instantly share code, notes, and snippets.

@alexhawkins
Last active August 29, 2015 13:57
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 alexhawkins/12af5b64c5cd7f8b1018 to your computer and use it in GitHub Desktop.
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 :&
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
@alexhawkins
Copy link
Author

Confused about when to use self again? This works the same without self. Also why use & instead :&

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