Bug #18799
closedRefinement#import_methods vs attr_reader
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.
Updated by jeremyevans0 (Jeremy Evans) over 1 year ago
- Status changed from Open to Closed