On December 5, 2015 at 20:13:48 MST, justcolin@gmail.com wrote:
Issue #9451 has been updated by Colin Fulton.
Is there any update on this feature? In Ruby 2.2.3 I still run into a problem where the unary & can not be used when the method was added with a refinement, such as the following:
`
module Example
refine String do
def pugs
"Pugs!"
end
end
end
using Example
puts ('a'..'z').map(&:pugs)
`
I can understand why they currently do not work, but it leads to uglier code.
----------------------------------------
Feature #9451: Refinements and unary & (to_proc)
https://bugs.ruby-lang.org/issues/9451#change-55254
* Author: Jan Lelis
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Not sure if this is a bug or feature request:
~~~ruby
require 'minitest/autorun'
require 'set'
module ClassToProc
refine Class do
def to_proc
lambda{ |*args| self.new(*args) }
end
end
end
using ClassToProc
describe 'Class#to_proc' do
it 'works when called directly' do
Set.to_proc[[1,2]].must_equal Set[1,2]
end
it 'fails when called via ampersand' do
[[1,2]].map(&Set).must_equal [Set[1,2]]
end
end
~~~
The second example errors with *NoMethodError: super: no superclass method `to_proc' for Set:Class*
Would be great to have it, though.
--
https://bugs.ruby-lang.org/