From: shyouhei@... Date: 2016-05-21T09:15:09+00:00 Subject: [ruby-core:75657] [Ruby trunk Feature#7314] Convert Proc to Lambda doesn't work in MRI Issue #7314 has been updated by Shyouhei Urabe. Shyouhei Urabe wrote: > Currently if a block starts with "lambda {", it behaves like a lambda. All others are proc. I have to apology that I forgot about stabby lambdas here. They behave like lamndas too. Anyways this doesn't change the fact that the way a Proc instance behaves, is statically determined when they are literally written. I think it is a good property. I'd like to +1 to Charles' proposal to add warning when people try converting a proc into lambda. ---------------------------------------- Feature #7314: Convert Proc to Lambda doesn't work in MRI https://bugs.ruby-lang.org/issues/7314#change-58792 * Author: Richard Schneeman * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- 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 ```ruby 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: ```ruby 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. -- https://bugs.ruby-lang.org/ Unsubscribe: