###################### #类变量 ###################### 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
黑洞@heidsoft
Github:https://github.com/heidsoft
微博:http://weibo.com/liuganbin
热衷云计算和大数据
关注CloudStack,OpenStack,Linux c/c++/python/java
关注研究新技术