Project

General

Profile

Actions

Bug #19731

closed

Can’t call an instance method inside an Endless method definition

Added by ttanimichi (Tsukuru Tanimichi) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
[ruby-core:113903]

Description

Can’t call an instance method inside an Endless method definition.

$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]

$ cat withend.rb
class A
  def show
    puts 'ok' if params
  end

  def params
    42
  end
end

A.new.show

$ ruby withend.rb
ok

$ cat endless.rb
class A
  def show = puts 'ok' if params

  def params
    42
  end
end

A.new.show

$ ruby endless.rb
endless.rb:2:in `<class:A>': undefined local variable or method `params' for A:Class (NameError)

  def show = puts 'ok' if params
                          ^^^^^^
	from endless.rb:1:in `<main>'
exit status: 1

But, the example below works fine. Is this an expected behavior?

$ cat endless2.rb
class A
  def show = puts params

  def params
    42
  end
end

A.new.show

$ ruby endless2.rb
42

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #19392: Endless method and parsing prioritiesClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0