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/9776009 to your computer and use it in GitHub Desktop.
Save alexhawkins/9776009 to your computer and use it in GitHub Desktop.
Changing class and using the Each Method
class Array
def sum_numbers
sum = 0
self.each { |num| sum += num }
sum
end
def add_index
self.each_with_index do |item, index|
self[index] = "#{index} is #{item}"
end
end
end
class String
def camel_case
words = self.split
words.each {|word| word.capitalize! }
words[0].downcase!
words.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment