有两种方法
1. 开源框架喜欢用的方式
class Test
class << self
def a
puts "static method"
end
end
end
2. 我喜欢用的方式
class Test
def self.a
puts "static method"
end
end
调用就很简单了
Test.a
有两种方法
1. 开源框架喜欢用的方式
class Test
class << self
def a
puts "static method"
end
end
end
2. 我喜欢用的方式
class Test
def self.a
puts "static method"
end
end
调用就很简单了
Test.a