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

Refinements not following inheritance #5541

Closed
HoneyryderChuck opened this issue Dec 27, 2018 · 4 comments
Closed

Refinements not following inheritance #5541

HoneyryderChuck opened this issue Dec 27, 2018 · 4 comments
Milestone

Comments

@HoneyryderChuck
Copy link

Environment

Provide at least:

  • JRuby version (jruby -v) : jruby 9.2.5.0 (2.5.0) 2018-12-06 6d5a228 OpenJDK 64-Bit Server VM 25.181-b13 on 1.8.0_181-b13 +jit [linux-x86_64]
  • Operating system and platform (e.g. uname -a): Linux 4d5914318003 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 Linux

Expected Behavior

I'm refining the URI::Generic class, the base class of all URI's:

module URIExtensions
   refine URI::Generic do
     def authority
        port_string = port == default_port ? nil : ":#{port}"
        "#{host}#{port_string}"
     end
   end
end

where I'll hopefully call this method in URI::HTTP and URI::HTTPS:

URI("http://bang.com:8080").authority #=> "bang.com:8080"

this works on CRuby 2.1 -> 2.5 (probably also 2.6, didn't run it yet)

Actual Behavior

This doesn't work:

URI("http://bang.com:8080").authority #=> NoMethodError: undefined method `authority' for #<URI::HTTP http://bang.com>

# however, this works:

```ruby
URI::Generic.new(scheme: "http", host: "bang.com", port: "8080").authority #=> "bang.com:8080"
@palkan
Copy link

palkan commented Jan 6, 2019

Looks like a duplicate of #5221

@enebo enebo modified the milestones: JRuby 9.2.6.0, JRuby 9.2.8.0 Jan 9, 2019
@enebo enebo modified the milestones: JRuby 9.2.6.0, JRuby 9.2.7.0 Feb 11, 2019
@headius
Copy link
Member

headius commented Feb 26, 2019

This is not fixed by #5627 but should be fixed by follow-up refinement work. The issue here is likely due to problems propagating refinements from parent scopes to child scopes at scope initiation time.

@headius
Copy link
Member

headius commented Apr 8, 2019

This appears to be fixed by the subsequent tweaks to super and refinements going into 9.2.7.0.

[] ~/projects/jruby $ cat blah.rb
module URIExtensions
  refine URI::Generic do
    def authority
      port_string = port == default_port ? nil : ":#{port}"
      "#{host}#{port_string}"
    end
  end
end

using URIExtensions

URI("http://bang.com:8080").authority
[] ~/projects/jruby $ rvm jruby-9.2.6.0 do jruby blah.rb
NoMethodError: undefined method `authority' for #<URI::HTTP http://bang.com:8080>
  <main> at blah.rb:12

[] ~/projects/jruby $ jruby -v blah.rb
jruby 9.2.7.0-SNAPSHOT (2.5.3) 2019-04-08 2122e9f OpenJDK 64-Bit Server VM 25.202-b08 on 1.8.0_202-b08 +jit [darwin-x86_64]

@headius headius closed this as completed Apr 8, 2019
@HoneyryderChuck
Copy link
Author

sweet ,thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants