单例模式

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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