gpt4 book ai didi

ruby - 你如何在不调用函数的情况下引用它,因为 foo 与 foo() 相同所以它已经被调用

转载 作者:数据小太阳 更新时间:2023-10-29 08:29:23 24 4
gpt4 key购买 nike

在 Ruby 中,如何在不调用函数的情况下引用它,因为 foo 与 foo() 相同,所以它已经被调用了。

例如,puts.classputs().class 相同

最佳答案

你使用方法,像这样:

o = Object.new
def o.do_it
puts "I did it!"
end

m = o.method(:do_it)
m.call # prints out "I did it!"

关于ruby - 你如何在不调用函数的情况下引用它,因为 foo 与 foo() 相同所以它已经被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3113140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com