使用以下代码,我希望用户输入"pluto"
or "scooby"
,然后调用该实例的speak()
方法。
class Dog
def speak()
puts "Woof"
end
end
scooby = Dog.new
pluto = Dog.new
puts "Which dog would you like to speak? [scooby/pluto]"
response = gets.chomp
response.speak()
如果你能告诉我怎么做,和/或怎么称呼它,那就太棒了。