0

Is there any possibility to establish in method_missing declaration in Ruby whether a given missing_method was called (without any arguments) using parentheses notation, ie:

foo.non_existing_method()

or using parentheses-less notation:

foo.non_existing_method

?

I need this to solve my very specific testing problem.

mgamer
  • 13,580
  • 25
  • 87
  • 145

1 Answers1

5

No.

Since both are exactly the same, there cannot possibly be a way to detect the difference.

It doesn't make sense anyway, since both are exactly the same, so there cannot possibly any behavorial difference, either.

If you could detect the difference, then you could also have your method behave differently, which would be extremely surprising to any user of that method.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • I suppose it's not a terribly surprising question, however, given the special case that `super` is different from `super()`. – Phrogz Dec 27 '10 at 16:55
  • @Phrogz: That's not a message send, though. – Jörg W Mittag Dec 27 '10 at 17:08
  • örgWMittag Right, but that this is the case is not obvious to end users, just as it's not obvious that `alias_method` is a method but `alias` is syntax, or that `&` may be implemented as a method but `&&` may not. My only point here is that there exists one case in the language where `xxx` behaves differently from `xxx()`, so it might not be _extremely_ surprising to some for a method to change its behavior based on invocation method. – Phrogz Dec 27 '10 at 17:31