Skip to content

Instantly share code, notes, and snippets.

@seanlinsley
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save seanlinsley/193b93d5854c433a2b18 to your computer and use it in GitHub Desktop.

Select an option

Save seanlinsley/193b93d5854c433a2b18 to your computer and use it in GitHub Desktop.
why no implicit arguments for super inside define_method?
# 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