Skip to content

Instantly share code, notes, and snippets.

@crguezl
Last active December 11, 2015 16:19
Show Gist options
  • Save crguezl/4627112 to your computer and use it in GitHub Desktop.
Save crguezl/4627112 to your computer and use it in GitHub Desktop.
class Array
def iterator!
self.each_with_index do |n,i|
self[i] = yield n
end
end
end
array = [1,2,5,6,7]
array.iterator! {|n| n**2}
puts array.inspect # [1, 4, 25, 36, 49 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment