Hello!
Is there something similar to method_missing for classes?
I.e. overload a method of Object or handle an exception
when a ‘Foo.new’ is called and class Foo does not exist.
Regards,
···
–
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky
Kent_S2
(Kent S.)
2
Try this:
$ irb
irb(main):001:0> defined? AClass
=> nil
irb(main):002:0> class AClass; end
=> nil
irb(main):003:0> defined? AClass
=> “constant”
irb(main):004:0>
Cheers,
Kent.
···
On May 7, 2004, at 12:58 PM, Elias Athanasopoulos wrote:
Hello!
Is there something similar to method_missing for classes?
I.e. overload a method of Object or handle an exception
when a ‘Foo.new’ is called and class Foo does not exist.
Regards,
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky
Something like this?
def Object.const_missing(sym)
Object.const_set( sym, Class.new() )
end
==>nil
Foo.new
==>#Foo:0x3c408
Bar.new
==>#Bar:0x398d4
Baz.new
==>#Baz:0x21370
···
On May 7, 2004, at 9:58 AM, Elias Athanasopoulos wrote:
Hello!
Is there something similar to method_missing for classes?
I.e. overload a method of Object or handle an exception
when a ‘Foo.new’ is called and class Foo does not exist.
Exactly! Thanx (to Dmitry also).
Ruby never fails to surprise - not in the common ‘bad’ sense - me!
Regards,
···
On Sat, May 08, 2004 at 03:09:15AM +0900, Mark Hubbart wrote:
On May 7, 2004, at 9:58 AM, Elias Athanasopoulos wrote:
Hello!
Is there something similar to method_missing for classes?
I.e. overload a method of Object or handle an exception
when a ‘Foo.new’ is called and class Foo does not exist.
Something like this?
def Object.const_missing(sym)
Object.const_set( sym, Class.new() )
end
==>nil
Foo.new
==>#Foo:0x3c408
Bar.new
==>#Bar:0x398d4
Baz.new
==>#Baz:0x21370
–
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky