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

Something funky with frozen string literals #164

Open
JoshCheek opened this issue Jul 4, 2021 · 0 comments
Open

Something funky with frozen string literals #164

JoshCheek opened this issue Jul 4, 2021 · 0 comments

Comments

@JoshCheek
Copy link
Owner

The magic comment at the top of this code example breaks the inspection

# frozen_string_literal: true
module RefineExport
  refine Module do
    # See https://bugs.ruby-lang.org/issues/17374#note-8
    def refine(what, export: false)
      mod = super(what)
      return mod unless export
      export = self if export == true

      export.module_eval do
        mod.instance_methods(false).each do |method|
          define_method(method, mod.instance_method(method))
        end
        mod.private_instance_methods(false).each do |method|
          private define_method(method, mod.instance_method(method))
        end
      end
      mod
    end
  end
end

module M
  using RefineExport
  # refine self, exports: [self, Object] do
  refine self do
    def a() = 1
    def b() = a
  end
end

include M
using M
(method(:b).methods - Object.new.methods).inspect
# => #<String:0x00000001569344d0>

b # => 1
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

1 participant