关于class<

module Lib
	class<<self
		def fuc
			puts "in Lib'fuc"
			puts self
		end
	end
end
class A
	include Lib
	def self.fuc
		puts "in A'fuc"
		puts self
	end
end

Lib.fuc
A.fuc

gets

  输出结果是

in Lib'fuc
Lib
in A'fuc
A

class<<self 相当于批量定义了 def self.someMethods

你可能感兴趣的:(ruby学习点滴)