attr_xxxxx 和:define_method

class Module
	 def class_attr_reader(*symbols)
	 	symbols.each do |symbol|
	 		self.class.send(:define_method,symbol) do
	 			class_variable_get( "@@#{symbol}" )
 		end
 		def class_attr_writter*symbols)
	 	symbols.each do |symbol|
	 		self.class.send(:define_method,"#{symbol}=") do
	 			class_variable_set( "@@#{symbol}" ,value)
 		end
 		
 	end
end

 

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