Project

General

Profile

Actions

Feature #12638

closed

Symbol#to_proc probable bug (seems not to support refinements)

Added by adrianomitre (Adriano Mitre) over 8 years ago. Updated about 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:76614]

Description

It is my understanding that

v.map { |x| x.foobar }

should always be equivalent to

v.map(&:foobar)

The following shows a case, involving refinements, where this is not the case.

module MyExtensions
  refine Object do
    def foobar
      self
    end
  end
end

class MyClass
  using MyExtensions
  def self.ok(ary)
    ary.map { |x| x.foobar }
  end

  def self.error(ary)
    ary.map(&:foobar)
  end
end
MyClass.ok([1]) #=> [1]
MyClass.error([1]) #=> NoMethodError: undefined method `foobar' for 1:Fixnum

PS: also affects ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #9451: Refinements and unary & (to_proc)Closedmatz (Yukihiro Matsumoto)Actions
Actions #1

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Is duplicate of Feature #9451: Refinements and unary & (to_proc) added

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Tracker changed from Bug to Feature
Actions #3

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Status changed from Open to Closed

Applied in changeset r56426.


vm_args.c: allow refinements in Symbol proc

  • vm_args.c (refine_sym_proc_call): search and call method with
    refinements.
  • vm_args.c (vm_caller_setup_arg_block): enable refinements when
    enabled in the caller. [Feature #9451]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0