makoto (owner)

Revisions

gist: 228704 Download_button fork
public
Public Clone URL: git://gist.github.com/228704.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# In Python.
# import yaml
#
# _config = None
# def get():
# global _config
# if not _config:
# data = open('config.yaml').read().decode('utf8')
# _config = yaml.load(data)
# return _config
 
# In Ruby
Config = {}
 
def get()
  if Config[:config]
    return Config[:config]
  else
    p "this should be printed only once if cached"
    data = File.open('config.yml')
    Config[:config] = YAML.load(data) # dynamic constant assignment error
    return Config[:config]
  end
end
p get()
p get()
# This is also possible, which will break encapsulation
# Config[:config]