中关村村草 发表于 2011-11-01 21:49

主题:Ruby定义静态方法

主题:Ruby定义静态方法
有两种方法

1. 开源框架喜欢用的方式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. 我喜欢用的方式


Ruby代码class Test   
   def self.a   
       puts "static method"
   end
end

class Test
   def self.a
       puts "static method"
   end
end 调用就很简单了

幽鬼-yg 发表于 2011-11-11 21:55

谢谢啊:em27:

cinanine 发表于 2011-11-14 02:54

一知半解啊
页: [1]
查看完整版本: 主题:Ruby定义静态方法