From: Yukihiro Matsumoto Date: 2008-10-07T23:57:31+09:00 Subject: Re: Difference between Foo = Class.new and class Foo Hi, In message "Re: Difference between Foo = Class.new and class Foo" on Tue, 7 Oct 2008 23:51:03 +0900, Brandon Dimcheff writes: |I'm playing around with classes and discovered that | |class Foo | ... |end | |and | |Foo = Class.new do | ... |end | |seem to behave slightly differently. I assumed that "class Foo" was |just a shortcut that got translated into "Foo = Class.new", but when I |muck with class in the following way: | |class Class | class << self | def new | puts "new called" | super | end | end |end | |and then do "Foo = Class.new", I get "new called" printed to stdout. |If I do "class Foo..." I get nothing. So it seems that the "class" |keyword does not end up calling new on Class when you define a new |class. Does anybody know what's going on here? Is something else |called instead? I think you're comparing the different code. See the following code: class Foo class << self def new puts "foo new called" super end end end Foo.new Bar = Class.new do class << self def new puts "bar new called" super end end end Bar.new -- matz.