【发布时间】:2015-04-17 07:05:00
【问题描述】:
我有点想知道,以下两种方法有什么区别吗?
-
使用self调用类方法和类方法
class Test def self.foo puts 'Welcome to ruby' end def self.bar self.foo end endTest.bar# 欢迎使用 ruby -
在没有self的类方法中调用类方法
class Test def self.foo puts 'Welcome to ruby' end def self.bar foo end endTest.bar# 欢迎使用 ruby
【问题讨论】:
-
请注意,这并不特定于类方法,调用实例方法也是如此。
标签: ruby