###################### #类变量 ###################### class Cloud @@count=0 def initialize(user,password,ip) @user = user @password =password @ip =ip end def createvm @ip =ip @@count+=1 end end ######################### #类方法和实例方法 ######################### class Example def instance_method puts "instance_method" end def Example.class_method puts "class class_method" end end e1 = Example.new() e1.instance_method class MyLogger private_class_method :new @@logger = nil##类变量 def MyLogger.create @@logger = new unless @@logger @@logger end end end
ruby 类方法、实例方法、类变量,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/heidsoft/p/3845450.html