Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make def_*_delegator return name of method defined (Fixes #10) #11

Merged
merged 2 commits into from
Dec 11, 2019

Conversation

jeremyevans
Copy link
Contributor

This restores compatibility with previous versions. This behavior
was previously undefined, but it makes sense for the name of the
defined method to be returned.

This restores compatibility with previous versions.  This behavior
was previously undefined, but it makes sense for the name of the
defined method to be returned.
@ashmaroli
Copy link

Upon further thought to this, I think it'd be better to use a guard clause instead of initializing a local variable.

  def def_instance_delegator(accessor, method, ali = method)
    gen = Forwardable._delegator_method(self, accessor, method, ali)

    # If it's not a class or module, it's an instance
    mod = Module === self ? self : singleton_class

    unless RUBY_VERSION >= '2.7'
      return mod.module_eval(&gen)
    end

    mod.send(:ruby2_keywords, ali)
  end

@jeremyevans
Copy link
Contributor Author

@ashmaroli I don't think that will work on Ruby 2.7+.

@ashmaroli
Copy link

I see.. Good to know that.
Thanks.

@hsbt hsbt merged commit 58e28f0 into ruby:master Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants