Last active
August 29, 2015 14:20
-
-
Save seanlinsley/193b93d5854c433a2b18 to your computer and use it in GitHub Desktop.
why no implicit arguments for super inside define_method?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # setup | |
| class User | |
| def name; 'Bob'; end | |
| end | |
| class Object | |
| def wrap(method, &block) | |
| prepend Module.new { define_method method, &block } | |
| end | |
| end | |
| # Working example | |
| class User | |
| wrap(:name) { 'I am ' + super() } | |
| end | |
| User.new.name == 'I am Bob' | |
| # Failing example | |
| class User | |
| wrap(:name) { 'I am ' + super } | |
| end | |
| User.new.name | |
| RuntimeError: implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment