Project

General

Profile

Actions

Bug #18799

closed

Refinement#import_methods vs attr_reader

Added by palkan (Vladimir Dementyev) almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-darwin21]
[ruby-core:108660]

Description

Currently, it's not possible to import methods defined as attr_{reader, accessor,writer}:

module M
  attr_reader :fuu
end

module R
  refine Object do
    import_methods M
  end
end

#=> Can't import method which is not defined with Ruby code: M#fuu (ArgumentError)

Is that a known/intentional limitation or a bug? From the error message it might seem that this is a bug (since attr_smth is a Ruby code).

Updated by palkan (Vladimir Dementyev) almost 2 years ago

UPD: looks like define_method is not supported, too:

module M
  define_method(:fuu) { }
end

module R
  refine Object do
    import_methods M
  end
end

#=> Can't import method which is not defined with Ruby code: M#fuu (ArgumentError)

Updated by Eregon (Benoit Daloze) almost 2 years ago

is not defined with Ruby code

It means the method's body is not Ruby code. And indeed, attr_* defines methods which are not defined in/with Ruby code.

So this seems expected.

Same for define_method, which has some internal wrapper around the given block and so cannot easily be import-ed.

Updated by shugo (Shugo Maeda) almost 2 years ago

As eregon stated, it's an intended limitation.

It's possible to allow importing C methods without refinements activation.
It may be helpful for attr_*, but not for define_method.

Actions #4

Updated by jeremyevans0 (Jeremy Evans) over 1 year ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0