Project

General

Profile

Bug #17193

Endless method definition doesn't work with lambdas in IRB

Added by kodnin (David Boot) about 1 month ago. Updated 6 days ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0preview1 (2020-09-25 master 0096d2b895) [x86_64-darwin19]
[ruby-core:100166]

Description

Endless method definition doesn't work with lambdas. Please check the attached screenshot.

def foo() = 123
# => :foo

foo
# => 123

def bar() = lambda { |x| x * x }
# I expected the method to be defined.

def bar() = ->(x) { x * x }
# Same issue.

Nice to have:

def bar = lambda { |x| x * x }
def bar = ->(x) { x * x }

Files

Screenshot 2020-09-26 at 09.19.24.png (714 KB) Screenshot 2020-09-26 at 09.19.24.png kodnin (David Boot), 09/26/2020 07:19 AM

Updated by wanabe (_ wanabe) about 1 month ago

I think this is an irb problem, not a ruby problem.

$ ruby -ve 'def bar() = lambda { |x| x * x };p bar'
ruby 3.0.0dev (2020-09-25T22:52:04Z master 137fa5b27e) [x86_64-linux]
#<Proc:0x00005582978039e0 -e:1 (lambda)>

Updated by kodnin (David Boot) about 1 month ago

wanabe (_ wanabe) wrote in #note-1:

I think this is an irb problem, not a ruby problem.

$ ruby -ve 'def bar() = lambda { |x| x * x };p bar'
ruby 3.0.0dev (2020-09-25T22:52:04Z master 137fa5b27e) [x86_64-linux]
#<Proc:0x00005582978039e0 -e:1 (lambda)>

I can confirm that this works indeed.

$ ruby -e 'def bar() = ->(x) { x * x }; puts bar.(3)'
9
#3

Updated by mame (Yusuke Endoh) 30 days ago

  • Subject changed from Endless method definition doesn't work with lambdas to Endless method definition doesn't work with lambdas in IRB

Updated by taiyoslime (Taiyo Mizuhashi) 6 days ago

This seems to be fixed in https://github.com/ruby/irb/pull/131. Please check it out.

Also available in: Atom PDF