From: Austin Ziegler Date: 2007-05-18T09:25:39+09:00 Subject: Re: Some Ruby Features missing... On 5/17/07, edlich@gmail.com wrote: > On 16 Mai, 21:17, "Adriano Ferreira" wrote: > > On 5/16/07, edl...@gmail.com wrote: > > As Stefano said, you can modify the methods of a class in Ruby anytime you want. > > irb> class Foo > > irb> attr_accessor :foo # here the conventional accessor is defined > > irb> > > irb* def foo # and here it is overriden > > irb> puts "foo invoked" > > irb> @foo > > irb> end > > irb> end > > => nil > > > > irb> Foo.new.foo > > foo invoked > > => nil > Unfortunately this is not at runtime. That's not true. class Foo; end Foo.new.foo # raises an exception class Foo; def foo; "hello"; end; end Foo.new.foo # "hello" If you want to modify just an object, then just do so: class Bar; end foo = Bar.new foo.baz # exception class << bar; def baz; "hello"; end; end foo.baz # "hello" Better: module BazMethod; def baz; "hello"; end; end foo = Bar.new foo.extend(BazMethod) foo.baz # "hello" There is no separate compile time in Ruby. -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca