From: "Morris, Chris" Date: 2001-11-06T05:58:42+09:00 Subject: [ruby-talk:24425] RE: Detect future method calls in method_missin g? BTW, I realize in this example I could simply test methId.id2name to see if it's "content" and react accordingly, but that'd only work in my example, not in my real context (ie ... it's not a great example :) ) > -----Original Message----- > From: Morris, Chris [mailto:chris.morris@snelling.com] > Sent: Monday, November 05, 2001 2:57 PM > To: ruby-talk@ruby-lang.org > Subject: [ruby-talk:24424] Detect future method calls in > method_missing? > > > Given this (contrived example for a real wrapper I'm writing): > > class MyClass > attr_reader :content, :contentLength > def initialize > @content = 'test' > @contentLength = @content.length > end > end > > class MyClassWrapper > def initialize > @mc = MyClass.new > end > > def method_missing(methID, *args) > methodName = methID.id2name > @mc.content.send(methodName.intern, *args) > end > end > > Used this way: > > w = MyClassWrapper.new > puts w.reverse > puts w.content.length > > Yields: > > tset > ./default.method.in.wrapper.rb:16:in `send': undefined > method `content' > for "test":String (NameError) > from ./default.method.in.wrapper.rb:16:in `method_missing' > from -:3 > > I understand why it does this. My question is this: is there > a way, when > w.content.length is called, from within > method_missing("content") to know > that ".length" will be coming next? (and in that case simply return > @mc.content). My guess is no, there's no way for > method_missing to know what > future calls are coming down the pipe. > > Chris >