Actions
Bug #19731
closedCan’t call an instance method inside an Endless method definition
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
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
Updated by mame (Yusuke Endoh) over 1 year ago
- Related to Bug #19392: Endless method and parsing priorities added
Updated by mame (Yusuke Endoh) over 1 year ago
Currently it is an expected behavior because it is parsed as (def show = puts 'ok') if params
. Related to #19392.
Updated by jeremyevans0 (Jeremy Evans) over 1 year ago
- Status changed from Open to Closed
Actions
Like0
Like0Like0Like0