Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kasei-san
Created August 3, 2014 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasei-san/3231b0db2c4241176598 to your computer and use it in GitHub Desktop.
Save kasei-san/3231b0db2c4241176598 to your computer and use it in GitHub Desktop.
Singleton パターンを用いると、そのクラスのインスタンスが1つしか生成されないことを保証することができる。 ロケールやLook&Feelなど、絶対にアプリケーション全体で統一しなければならない仕組みの実装に使用される
require 'singleton'
# 設定ファイルの情報を格納する class
#
class Setting
def self.[](key)
settings(key)
end
def self.settings
@@settings ||= YAML.load_file("settings.yml")
end
end
Setting['name']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment