add some exercises
This commit is contained in:
1 parent
f6abf65e91
commit
d79c543c72
13 files changed
+232
No files matched your search
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
class Gecko
|
||||
def initialize(name)
|
||||
@name = name
|
||||
@meals = []
|
||||
end
|
||||
|
||||
def eat(prey, quantity)
|
||||
@meals << [prey, quantity]
|
||||
end
|
||||
|
||||
def display_meals
|
||||
puts "#{@name} a mangé :"
|
||||
|
||||
total = 0
|
||||
|
||||
@meals.each do |prey, quantity|
|
||||
total += quantity
|
||||
puts "- #{quantity} #{prey}"
|
||||
end
|
||||
|
||||
puts
|
||||
puts "Total : #{total} proies"
|
||||
end
|
||||
end
|
||||
|
||||
delta = Gecko.new("Delta")
|
||||
|
||||
delta.eat("dubia", 2)
|
||||
delta.eat("ver de farine", 3)
|
||||
delta.eat("cloporte", 1)
|
||||
|
||||
delta.display_meals
|
||||
Reference in new issue
Block a user