Last active
August 29, 2015 13:57
-
-
Save alexhawkins/9776009 to your computer and use it in GitHub Desktop.
Changing class and using the Each Method
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 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