What is the correct way to write a singleton pattern in Ruby?

前端 未结 3 1016
心在旅途
心在旅途 2021-01-30 11:31

I\'m trying to write the most secure singleton in Ruby that I can. I\'m new to the language, which is so elastic that I don\'t have a strong feeling that my singleton class wil

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 12:08

    require 'singleton'
    class Klass
        include Singleton
        # ...
    end
    

    See the Ruby Standard Library Singleton class documention for an explanation.

提交回复
热议问题