Project

General

Profile

Actions

Feature #9451

closed

Refinements and unary & (to_proc)

Added by rbjl (Jan Lelis) about 10 years ago. Updated over 7 years ago.

Status:
Closed
Target version:
-
[ruby-core:60109]

Description

Not sure if this is a bug or feature request:

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.


Related issues 2 (0 open2 closed)

Has duplicate Ruby master - Feature #12638: Symbol#to_proc probable bug (seems not to support refinements)ClosedActions
Has duplicate Ruby master - Feature #12079: Loosening the condition for refinementRejectedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0