Created
August 3, 2014 03:49
-
-
Save kasei-san/3231b0db2c4241176598 to your computer and use it in GitHub Desktop.
Singleton パターン ref: http://qiita.com/kasei-san/items/3d3e13cf6f3d598dcceb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Singleton パターンを用いると、そのクラスのインスタンスが1つしか生成されないことを保証することができる。 ロケールやLook&Feelなど、絶対にアプリケーション全体で統一しなければならない仕組みの実装に使用される |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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