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
···
On 5/17/07, edlich@gmail.com <edlich@gmail.com> wrote:
On 16 Mai, 21:17, "Adriano Ferreira" <a.r.ferre...@gmail.com> wrote:
> On 5/16/07, edl...@gmail.com <edl...@gmail.com> wrote:
> As Stefano said, you can modify the methods of a class in Ruby anytime you want.
> > class Foo
> > attr_accessor :foo # here the conventional accessor is defined
> >
> irb* def foo # and here it is overriden
> > puts "foo invoked"
> > @foo
> > end
> > end
> => nil
>
> > Foo.new.foo
> foo invoked
> => nil
Unfortunately this is not at runtime.
--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
* austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
* austin@zieglers.ca