带有可选参数的方法 [英] A method with an optional parameter
本文介绍了带有可选参数的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让方法可以接受一个参数,但也可以不带参数调用,在这种情况下,参数被视为nil
,如下所示?
Is there a way to make a method that can accept a parameter, but can also be called without one, in which case the parameter is regarded nil
like the following?
some_func(variable)
some_func
推荐答案
def some_func(variable = nil)
...
end
这篇关于带有可选参数的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文