具有可选参数的方法 [英] 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屋!
查看全文