Rubyのシングルトンが好きだけどもっとうまく使いこなしたいので例
require 'singleton'
class Foo
include Singleton
def initialize
# code to setup singleton here
end
def self.get_bar
Foo.instance.get_bar
end
def get_bar
end
def get_nar
end
end
使用法
Foo.instance.get_bar
(デフォルト)またはFoo.get_bar
(私が作成した静的self.get_bar
メソッドのため)
メソッドごとに静的ラッパーを作成しなくても、すべてのメソッドにアクセスできるようにするエレガントな方法はありますか? メソッドごとに書く必要があるのは冗長に思えます.instance
アップデート
ルビー 1.8.7