Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refinements in eval with binding #6017

@palkan

Description

@palkan

Environment

  • JRuby version: jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM 25.232-b09 on 1.8.0_232-b09 +jit [linux-x86_64]
  • Operating system and platform: Linux c2e6ee70592c 4.9.125-linuxkit break script engine #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 GNU/Linux

Expected Behavior

Expected this script to behave the same way as in MRI 2.6.5:

# test.rb
using(Module.new do
  refine String do
    def foo
      "bar"
    end
  end
end)

eval "\n#{<<~'END_of_GUARD'}", binding, __FILE__, __LINE__
  p "foo".foo
END_of_GUARD
$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

$ ruby test.rb
"bar"

Actual Behavior

$ ruby -v
jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM 25.232-b09 on 1.8.0_232-b09 +jit [linux-x86_64]

$ ruby test.rb
NoMethodError: undefined method `foo' for "foo":String
Did you mean?  fork
  <main> at tmp/eval_refine.rb:10
    eval at org/jruby/RubyKernel.java:1061
  <main> at tmp/eval_refine.rb:9

Moving using into eval resolves the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions