Skip to content

Instantly share code, notes, and snippets.

@fresh5447
Created February 19, 2014 21:37
Show Gist options
  • Save fresh5447/9102188 to your computer and use it in GitHub Desktop.
Save fresh5447/9102188 to your computer and use it in GitHub Desktop.
Specs: describe "Array" do describe "sum_numbers" do it "sums consecutive numbers" do [1,2,3].sum_numbers.should eq(6) end it "sums random numbers" do [5,23,4].sum_numbers.should eq(32) end end end describe "String" do describe "camel_case" do it "leaves first word lowercase" do "test".camel_case.should eq("test") end it "should lowercase first …
class String
def camel_case
# "this is A TEST"
array_of_words = self.split
# ["this","is","A","TEST"]
array_of_words.each do |foo|
# "this"
foo.capitalize!
# "This"
end
# ["This", "Is", "A", "Test"]
array_of_words.first.downcase!
# ["this", "Is", "A", "Test"]
array_of_words.join # "thisIsATest"
end
end
p "test".camel_case
p [0,1,2,3].sum_numbers
p ["apple", "banana", "orange"].add_index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment