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
Actions
Like0
Like0Like0Like0