From: Brandon Dimcheff Date: 2008-10-08T00:16:46+09:00 Subject: Re: Difference between Foo = Class.new and class Foo hmm, interesting. I'm definitely going to have to use set_trace_func more often. Do you know if there's any way to tell which c function is being called for the c-calls? Like how does the ruby method "inherited" map to rb_... in MRI? Thanks, Brandon On Oct 7, 2008, at 10:56, Robert Klemme wrote: > 2008/10/7 Brandon Dimcheff : >> 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? > > Looks like there is a shortcut: > > 16:55:57 bas$ ruby -e 'set_trace_func lambda {|*a|p a}; class Foo;end' > ["line", "-e", 1, nil, #, false] > ["c-call", "-e", 1, :inherited, #, Class] > ["c-return", "-e", 1, :inherited, #, Class] > ["class", "-e", 1, nil, #, false] > ["end", "-e", 1, nil, nil, false] > 16:56:13 bas$ ruby -e 'set_trace_func lambda {|*a|p a}; Foo=Class.new' > ["line", "-e", 1, nil, #, false] > ["c-call", "-e", 1, :new, #, Class] > ["c-call", "-e", 1, :initialize, #, Class] > ["c-call", "-e", 1, :inherited, #, Class] > ["c-return", "-e", 1, :inherited, #, Class] > ["c-return", "-e", 1, :initialize, #, Class] > ["c-return", "-e", 1, :new, #, Class] > 16:56:44 bas$ > > If you need hooks for class creation look closely at ":inherited" > above. > > Kind regards > > robert > > -- > remember.guy do |as, often| as.you_can - without end >