Skip to content

Instantly share code, notes, and snippets.

@kennyt
Created October 27, 2012 09:47
Show Gist options
  • Save kennyt/3963805 to your computer and use it in GitHub Desktop.
Save kennyt/3963805 to your computer and use it in GitHub Desktop.
14_array_extensions
class Array
def sum
answer = 0
self.each do |number|
answer = answer + number
end
answer
end
def square
answer = []
self.each do |number|
answer << number*number
end
answer
end
def square!
counter = 0
self.length.times do
self[counter] = self[counter] * self[counter]
counter +=1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment