【发布时间】:2018-06-10 14:24:12
【问题描述】:
我需要知道是否可以从类方法调用类方法以及如何调用。
我的模型上有一个类,我的一个类方法变长了:
def self.method1(bar)
# Really long method that I need to split
# Do things with bar
end
所以我想把这个方法分成2个方法。类似的东西
def self.method1(bar)
# Do things with bar
# Call to method2
end
def self.method2(bar)
# Do things
end
它们都必须是类方法
如何从 method1 调用此 method2?
谢谢。
【问题讨论】:
-
当然你可以打这个电话。你试过了吗?你收到错误了吗?您可能需要使用
self.来限定它:self.method2(bar)。 -
如果它们在你通常调用 method2(bar) 的类中
标签: ruby class-method