单例模式

2014-12-14 0 648
单例模式
class SingleSimple
  def initialize
    @log=File.open("sy.txt","a+")
  end
  @@instance=SingleSimple.new
  
  def self.instance
    return @@instance
  end
  
  def write(msg)
    @log.puts msg
  end
  
  def read
    msg=@log.read
    return msg
  end
end

singlesimple1=SingleSimple::instance
singlesimple2=SingleSimple::instance
puts singlesimple1
puts singlesimple2

遇见资源网 ruby 单例模式 http://www.ox520.com/16163.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务