JoshCheek / seeing_is_believing

Displays the results of every line of code in your file
1.31k stars 54 forks source link

Something funky with frozen string literals #164

Open JoshCheek opened 3 years ago

JoshCheek commented 3 years ago

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