RosettaCodeData/Task/Singleton/Ruby/singleton.rb

10 lines
246 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
require 'singleton'
class MySingleton
include Singleton
# constructor and/or methods go here
end
a = MySingleton.instance # instance is only created the first time it is requested
b = MySingleton.instance
puts a.equal?(b) # outputs "true"