Project

General

Profile

Actions

Bug #17193

closed

Endless method definition doesn't work with lambdas in IRB

Added by kodnin (David Boot) over 3 years ago. Updated over 3 years ago.

Status:
Closed
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) over 3 years 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) over 3 years 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
Actions #3

Updated by mame (Yusuke Endoh) over 3 years 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) over 3 years ago

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

Updated by aycabta (aycabta .) over 3 years ago

  • Status changed from Open to Closed

As @taiyoslime (Taiyo Mizuhashi) said, I confirmed that it was fixed in https://github.com/ruby/irb/pull/131.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0