From: nobu@... Date: 2014-04-30T02:01:31+00:00 Subject: [ruby-core:62227] [ruby-trunk - Feature #9786] [Rejected] refinement & map(&:refinement_method) does not work Issue #9786 has been updated by Nobuyoshi Nakada. Description updated Status changed from Open to Rejected Refinements does affects to the current scope only. And `Symbol#to_proc` is independent from the callers context. A block works as you expect: ~~~ruby puts a.map {|x| x.add_z} ~~~ ---------------------------------------- Feature #9786: refinement & map(&:refinement_method) does not work https://bugs.ruby-lang.org/issues/9786#change-46374 * Author: Daniel Lo * Status: Rejected * Priority: Low * Assignee: * Category: * Target version: ---------------------------------------- Greetings! Thank you for your hard work on ruby, I love the language. I encountered an oddity, in which, I expected a refinement to be available and it wasn't. Here is the sample code using: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux] ~~~ $ irb irb(main):001:0> module MyRefinement irb(main):002:1> refine Fixnum do irb(main):003:2* def add_z irb(main):004:3> self.to_s + 'z' irb(main):005:3> end irb(main):006:2> end irb(main):007:1> end => # irb(main):008:0> irb(main):009:0* irb(main):010:0* class Test irb(main):011:1> using MyRefinement irb(main):012:1> irb(main):013:1* a = [ 1, 2 ] irb(main):014:1> puts a.map(&:to_s) irb(main):015:1> puts '-----' irb(main):016:1> puts a.first.add_z irb(main):017:1> puts '-----' irb(main):018:1> puts a.map(&:add_z) irb(main):019:1> end 1 2 ----- 1z ----- NoMethodError: super: no superclass method `add_z' for 1:Fixnum from (irb):18:in `map' from (irb):18:in `' from (irb):10 from /usr/local/bin/irb:11:in `
' irb(main):020:0> ~~~ Here is the code without the irb comments: ~~~ruby module MyRefinement refine Fixnum do def add_z self.to_s + 'z' end end end class Test using MyRefinement a = [ 1, 2 ] puts a.map(&:to_s) puts '-----' puts a.first.add_z puts '-----' puts a.map(&:add_z) end ~~~ Thank you! -daniel -- https://bugs.ruby-lang.org/