Class_missing?

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

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

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.
Try:

ri const_missing

···

On Saturday 08 May 2004 00:58, Elias Athanasopoulos wrote:

Regards,


sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here → postmaster@sco.com

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). :slight_smile:

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