Skip to content

Something funky with frozen string literals #164

@JoshCheek

Description

@JoshCheek

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions