feiyang10086 发表于 2011-10-29 20:07

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

cinanine 发表于 2011-11-01 14:44

技巧!!
页: [1]
查看完整版本: Ruby定义静态方法