If both a method and a variable has the same name it will use the variable.
hello = "hello from variable"
def hello
"hello from method"
end
puts hello
Is it possible somehow to use the method instead without changing name?
Try this:
puts hello()
The ambiguity between local variables and methods only arises for receiverless message sends with no argument list. So, the solution is obvious: either provide a receiver or an argument list:
self.hello
hello()
See also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With