module Powers
def outer_method name, &block
puts "outer method works"
yield
end
def inner_method name, &block
puts "inner method works ONLY inside outer method"
yield
end
end
class Superman
include Powers
def attack
outer_method "fly to moon" do
inner_method "take a dump" do
p "feels good and earth is safe"
end
end
inner_method "take a dump" do
p "earth is doomed"
end
end
Superman.new.attack
如何强制inner_method只能从outer_method内部的上下文中调用并拯救地球?