Skip to content

Instantly share code, notes, and snippets.

@geapi
Created May 7, 2010 13:11
Show Gist options
  • Save geapi/393399 to your computer and use it in GitHub Desktop.
Save geapi/393399 to your computer and use it in GitHub Desktop.
class SliceOfCake
@@totalSlices = 0
def initialize
@@totalSlices +=1
end
def getNumberOfSlices
if(@@totalSlices == 0)
"sorry no slices yet"
elsif (@@totalSlices == 1)
"there is #{@@totalSlices} slice of cake"
else
"there are #{@@totalSlices} slices of cake"
end
end
end
slice = SliceOfCake.new
slice2 = SliceOfCake.new
puts slice.getNumberOfSlices #=> there are 2 slices of cake
puts slice2.getNumberOfSlices #=> there are 2 slices of cake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment