From: Florian Frank Date: 2002-11-22T01:00:12+09:00 Subject: Re: Inheriting from FalseClass fails On 2002-11-20 03:29:53 +0900, Benedikt Rosenau wrote: > Consider this code snippet: > > class Klass < FalseClass > def initialize(*args) > puts "It works" > end > end > > 'ruby -v example.rb' gives: > ruby 1.6.8 (2002-11-07) [i686-linux] > example.rb:2: warning: overriding global function `initialize' > example.rb:7: undefined method `new' for Klass:Class (NameError) > > Klass.methods shows that Klass is indeed missing the method new. > The same applies for FalseClass. > > > Is it possible to inherit from FalseClass (or NilClass, for that > matter)? It doesn't work because "new" is explicitly undefined in object.c. FalseClass ist just the class of the sole object "false" and can't be instantiated. However, if you want to add methods to FalseClass you can just reopen it: class FalseClass def foo "foo" end end ==>nil false.foo ==>"foo" -- Java and C++ make you think that the new ideas are like the old ones. Java is the most distressing thing to hit computing since MS-DOS. -- Alan Kay