######################
#类变量
######################
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

 

posted on 2014-07-15 19:32  heidsoft  阅读(256)  评论(0编辑  收藏  举报