Are there equivalents to Ruby's method_missing in other languages?

前端 未结 15 1674
渐次进展
渐次进展 2020-12-08 08:00

In Ruby, objects have a handy method called method_missing which allows one to handle method calls for methods that have not even been (explicitly) defined:

15条回答
  •  不知归路
    2020-12-08 08:51

    I was looking for this before, and found a useful list (quickly being overtaken here) as part of the Merd project on SourceForge.


     Construct                          Language
    -----------                        ----------
     AUTOLOAD                           Perl
     AUTOSCALAR, AUTOMETH, AUTOLOAD...  Perl6
     __getattr__                        Python
     method_missing                     Ruby
     doesNotUnderstand                  Smalltalk
     __noSuchMethod__(17)               CoffeeScript, JavaScript
     unknown                            Tcl
     no-applicable-method               Common Lisp
     doesNotRecognizeSelector           Objective-C
     TryInvokeMember(18)                C#
     match [name, args] { ... }         E
     the predicate fail                 Prolog
     forward                            Io
    

    With footnotes:

    • (17) firefox
    • (18) C# 4, only for "dynamic" objects

提交回复
热议问题