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

alias_method inside refine causes `alias_method': undefined method for module #1942

Closed
deepj opened this issue Feb 28, 2020 · 3 comments
Closed
Assignees
Milestone

Comments

@deepj
Copy link

deepj commented Feb 28, 2020

To reproduce:

module SnakeCase
  refine ::String do
    def snake_case
    end

    alias_method :snakecase, :snake_case
  end
end

Error:

ref.rb:6:in `alias_method': undefined method `snake_case' for module `#<Module:0x200>' (NameError)
	from ref.rb:6:in `block in SnakeCase'
	from ref.rb:2:in `refine'
	from ref.rb:2:in `SnakeCase'
	from ref.rb:1:in `<main>'
@alecgorge
Copy link

I am experimenting with TruffleRuby as well and ran into the same issue. alias/alias_method works for existing methods but not methods declared inside the refinement.

Here is a simple set of cases for reproduction:

module ExampleRefinements
  # DOESN'T WORK
  refine Integer do
    def testing
      self.abs
    end
    # or alias_method
    alias test testing
  end

  # WORKS
  # refine Integer do
  #   def testing
  #     self.abs
  #   end
  #
  #   def test
  #     testing
  #   end
  # end

  # WORKS
  # refine Integer do
  #   def testing
  #     self.abs
  #   end
  #   # or alias_method
  #   alias test abs
  # end
end

using ExampleRefinements
puts -1.testing
puts -1.test
puts -1.testing == -1.test

Expected output:

1
1
true

@eregon eregon added the priority label Mar 4, 2020
@aardvark179 aardvark179 self-assigned this Mar 4, 2020
@deepj
Copy link
Author

deepj commented May 1, 2020

@eregon this is fixed in #1988

@eregon eregon closed this as completed May 1, 2020
@eregon eregon added this to the 20.2.0 milestone May 1, 2020
@eregon
Copy link
Member

eregon commented May 1, 2020

(this was actually fixed before, in d31d48f)

@eregon eregon modified the milestones: 20.2.0, 20.1.0 May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants