ruby 两种静态法
ruby 两种静态法1.不用self
Ruby代码class Test
class << self
def a
puts "static method"
end
end
end
class Test
class << self
def a
puts "static method"
end
end
end 2. self的方式
Ruby代码Ruby代码class Test
def self.a
puts "static method"
end
end
class Test
def self.a
puts "static method"
end
end调用
Ruby代码 Ruby代码Test.a Test.a 转自:http://www.iteye.com/topic/1116041 这个就是所谓类方法吧。。 实际是类的单态方法,还可以在Test类外部定义。 ruby
类的方法定义方式啊~
def 类的名称或者self .方法名称
class << 类的名称或者self
def 方法名称 还有其他的方法啊。
页:
[1]