Project

General

Profile

Actions

Feature #7314

open

Convert Proc to Lambda doesn't work in MRI

Added by schneems (Richard Schneeman) about 12 years ago. Updated over 8 years ago.

Status:
Assigned
Target version:
-
[ruby-core:49112]

Description

I have code where I need to convert a proc to a lambda (i need to be able to return out of the block). I would expect that passing a proc into a lambda to return a lambda. When I run this code on MRI i do not get the result I would expect

my_proc = proc { |x| x }
my_lambda = lambda &my_proc
my_lambda.lambda?

The result is false but I would expect it to be true

There is currently a way to turn a proc into a lambda in MRI like this:

def convert_to_lambda &block
  obj = Object.new
  obj.define_singleton_method(:_, &block)
  return obj.method(:_).to_proc
end

But this feels like a hack, and is not supported across other implementations. I would expect that passing a proc into a lambda to return a lambda, I believe it is a bug.


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #12957: A more OO way to create lambda ProcsFeedbackActions
Related to Ruby master - Feature #15973: Let Kernel#lambda always return a lambdaClosedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0