require 'singleton'
class Robot
include Singleton
private
def initialize
puts 'initialize singleton object'
end
end
Robot.instance
Robot.instance
看到这么简单的实现, java程序员瞬间哭晕.
require 'singleton'
class Robot
include Singleton
private
def initialize
puts 'initialize singleton object'
end
end
Robot.instance
Robot.instance
看到这么简单的实现, java程序员瞬间哭晕.
本文标题:Ruby中的Singleton
本文链接:https://www.haomeiwen.com/subject/jajeqttx.html
网友评论