class Config
#类型常量
@@MaxConnections = 3
# 类型字段
@@host = "10.0.0.1"
@@port = 3306
# 类型方法
def self.getConnection
"#{@@host}:#{@@port}"
end
def self.setHost(host)
@@host = host
end
end
connection = Config.getConnection()
# connection is "10.0.0.1:3306"
puts "connection is #{connection}"
Config.setHost("10.0.0.3")
connection = Config.getConnection()
# connection is "10.0.0.3:3306"
puts "connection is #{connection}"