本文介绍了方法名和变量名相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果方法和变量的名称相同,则将使用该变量.
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?
推荐答案
试试这个:
puts hello()
这篇关于方法名和变量名相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!