修改
class Tof
def Tof.etiology
puts "NS displacement of the infundibular septum"
end
def Tof.pathophys
puts "VSD, Overriding of the Aorta, RVH, pulmonary stenosis"
end
end
puts "What would you like to know?"
如何让用户输入Tof.etiology,以便puts语句显示
答案 0 :(得分:1)
(有问题的新代码的编辑答案)
您应该能够通过简单的继承来实现它。
class Foo
def m1
puts "method 1"
end
# ...
def m7
puts "method 7"
end
end
class Bar < Foo
end
class Baz < Foo
end
bar = Bar.new
bar.m1 # method 1
baz = Baz.new
baz.m1 # method 1
你也可以制作模块Foo并使用mixin。
可以使用初始答案处理第二部分:
puts "what would you like to know?"
answer = gets.chomp
case answer
when "Tof.etiology"
Tof.etiology
when "Tof.othermethod"
Tof.othermethod
end