I would like to call a method of a Singleton Object without the reference to its instance
SingletonKlass.my_method
instead of
SingletonKlass.instance.my_method
i've came up with this solution (using method_missing in the class):
require 'singleton'
class SingletonKlass
include Singleton
def self.method_missing(method, *args, &block)
self.instance.send(method, *args)
end
def my_method
puts "hi there!!"
end
end
is there any drawback to this ? is there any better solution ? any recommendation from you ?
thank you.
UPDATE:
my aim is to have a module to be mixed-in with singleton classes:
module NoInstanceSingleton
def method_missing(method, *args)
self.instance.send(method, *args)
end
end
end then use it in the class:
class SingletonKlass
include Singleton
extend NoInstanceSingleton
def method1; end
def method2; end
...
def methodN; end
end
i want to be able to directly call:
SingletonKlass.method1