Ruby定义静态方法
Ruby定义静态方法有两种方法
1. 开源框架喜欢用的方式
Ruby代码1.class Test
2. class << self
3. def a
4. puts "static method"
5. end
6. end
7.end
class Test
class << self
def a
puts "static method"
end
end
end 2. 我喜欢用的方式
Ruby代码1.class Test
2. def self.a
3. puts "static method"
4. end
5.end
class Test
def self.a
puts "static method"
end
end 调用就很简单了
Ruby代码1.Test.a 技巧!!
页:
[1]