I am doing some metaprogramming in ruby and in the method_missing implementation I wonder If i can tell if the call site is being used in an assignment ?
For example :
x = special_function 'param'
would be caught by the method_missing implementation. I would like to know if I can tell if the function was invoked like this :
special_function 'param'
I.e. without a left hand side on the assignment.
Is it possible in ruby to tell the difference between the above two examples in code ?
I wouldn’t think this is possible, simply because every method always returns something and evaluating a method is independent of the context in which it is called.
The assignment is incidental in this case and just happens to make use of what the method returns.
Is there a reason you want to distinguish these calls? Maybe there are other ways to look at the same problem by following a naming convention in your methods to help you separate their uses.