From: Lionel Thiry Date: 2005-04-19T02:14:36+09:00 Subject: Re: [ANN] Article: Seeing Metaclasses Clearly mark sparshatt a �crit : > why the lucky stiff wrote: > >> I've written a very nuts+bolts article on metaclasses (aka virtual >> classes or metaobjects), since they still lurk under a shroud of fear >> and enigma. >> >> >> >> I'm hoping this will help uncover the truth. If anything is unclear, >> please report it. Shed a light. >> > > One thing I found confusing was the comment for the class_def method > > ># Just defines a class method > >def class_def name, &blk > > class_eval { define_method name, &blk } > >end > > > However it actually defines an instance method > > require "metaid" > > class MyClass > class_def "class_method" do puts "success" end > end > > MyClass.class_method > #=> undefined method "class_method" for MyClass:Class > > MyClass.new.class_method #=> success > The only I've found to make your sample code work is to refactor class_def this way: def class_def name, &blk meta_eval { define_method name, &blk } end I personnaly feel it weird I could not realise this whithout the help of the metaclass manipulation methods _why has added. -- Lionel Thiry