编辑代码

#JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
class Foo
  def bar
    puts'Base Bar!'
  end
end

obj = Foo.new

obj.define_singleton_method(:new_bar) do
   puts "new Bar!"
end

obj.new_bar # Output - new Bar!
obj.bar # Output - Base Bar!