I would like to call a method of a Singleton Object without the reference to its instance
SingletonKlass.my_method
instead of
S
Using forwardable and def_delegators:
require 'singleton'
require 'forwardable'
class SingletonKlass
include Singleton
class << self
extend Forwardable
def_delegators :instance, :my_method
end
def my_method
puts "hi there!!"
end
end
SingletonKlass.my_method
Edit: If you want to include all the methods you've defined yourself, you could do
require 'singleton'
require 'forwardable'
class SingletonKlass
include Singleton
def my_method
puts "hi there!!"
end
class << self
extend Forwardable
def_delegators :instance, *SingletonKlass.instance_methods(false)
end
end
SingletonKlass.my_method