Here I tried once more to explain what I was looking for:
class Foo
def test
p "hi"
end
end
foo = Foo.new
foo.test # => "hi"
Foo.define_method(:test){p "hello"}
# private method `define_method' called for Foo:Class (NoMethodError)
Any method is there to re-define the method `test` without re-opening
the class in runtime?
Foo.class_eval do
define_method(:test){p 'hello'}
end
or you can use send:
Foo.send :define_method, :test, &proc{p 'hello'}
I hope this helps
Stefano
···
On Tuesday 23 July 2013 Love U Ruby wrote
Sorry for creating the confusions:-
Here I tried once more to explain what I was looking for:
class Foo
def test
p "hi"
end
end
foo = Foo.new
foo.test # => "hi"
Foo.define_method(:test){p "hello"}
# private method `define_method' called for Foo:Class (NoMethodError)
Any method is there to re-define the method `test` without re-opening
the class in runtime?