Да такое возможно сделать, вот набросал код вроде работает :)))
class A
class CallProxy
def initialize(obj, name)
@call_chain = [name]
@obj = obj
end
def method_missing(name, *args)
@call_chain << name
case
when good_chain?([:func, :name])
same_chain?([:func, :name]) ? @obj.func_name(*args) : self
else
fail "Invalid func: #{@call_chain.join('.')}"
end
end
def good_chain?(chain)
chain[0..@call_chain.length] == @call_chain
end
def same_chain?(chain)
chain == @call_chain
end
end
def method_missing(name, *args)
CallProxy.new(self, name)
end
def func_name(param)
param * 3
end
end
obj = A.new
puts obj.func.name('Blah')
puts obj.func.oops('Blah')