From: Michael Fellinger Date: 2006-12-15T18:14:33+09:00 Subject: Re: method_missing question On 12/15/06, Peter Szinek wrote: > Hello, > > I am using method_missing to build a structure (similar to a tree) like > this: > > P.book do > P.title > P.price > end > > class P > def self.method_missing(method_name, *args, &block) > #add a node with name 'method_name.to_s' to the tree etc. > end > end > > Now, the problem is I would like to write the above example like this: > > book do > title > price > end > > i.e. without the Ps. > P's sole purpose is to define method_missing - I did not want to > override Object.method_missing since I would like to release this code > to the wild and I think it could collide with my potential future user's > Object.method_missing. > > I have then experimented with modules (mimicking namespace > functionality) but that still did not provide the possibility to omit > the class name. I would need something equivalent to include - you can > omit the module name if you include the module - but with classes. > > I have no idea if this is possible in Ruby, but is there something like > run this code in a different context or something? actually, there is - it is called script and you can find it described here: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/100429 > TIA, > Peter > > __ > http://www.rubyrailways.com