方法名和变量名相同 [英] Method and variable name is the same

查看:42
本文介绍了方法名和变量名相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果方法和变量的名称相同,则将使用该变量.

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()

这篇关于方法名和变量名相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆