How can we create instance method and class methods at runtime in ruby?

class Foo
  def test
    p "hi"
  end
end
foo = Foo.new
foo.test # => "hi"
class Foo
  def test
    p "hiyy"
  end
end
foo.test
# >> "hi"
# >> "hiyy"

How Can I re-define the `test` method at runtime? I tried
`define_method`,but it didn't work for this.

-- 
Posted via http://www.ruby-forum.com/.