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