Skip to content

Instantly share code, notes, and snippets.

@diegoromera
Created April 7, 2012 15:26
Show Gist options
  • Save diegoromera/2329721 to your computer and use it in GitHub Desktop.
Save diegoromera/2329721 to your computer and use it in GitHub Desktop.
diego_unicorn_ruby_workshop
class Unicorn
def initialize(horn_length,gconsumed)
@horn_length = horn_length
@gconsumed = gconsumed
end
def eatglitter(amount)
@gconsumed += amount
end
def grownhorn
@horn_lenght = @horn_length + 1
end
def make_rainbow
size=@gconsumed + @horn_length
Rainbow.new(size)
end
end
class Rainbow
def initialize(size)
@size=size
end
def size
@size
end
end
harry = Unicorn.new(6,4)
sally = Unicorn.new(10,3)
harry.eatglitter(5)
sally.eatglitter(6)
r1 = harry.make_rainbow
r2 = sally.make_rainbow
if r1.size > r2.size
harry.growhorn
puts "harry"
else if r1.size < r2.size
sally.grownhorn
puts "sally"
else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment