makoto (owner)

Revisions

gist: 228707 Download_button fork
public
Public Clone URL: git://gist.github.com/228707.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
30
# In Python
# import yaml
#
# def _get_from_disk():
# data = open('config.yaml').read().decode('utf8')
# config = yaml.load(data) # クロージャ内に隠蔽・保持されるローカル変数
# global get
# get = lambda : config # 二回目からはconfigを返す無名関数を呼ぶ様に変更
# return get()
#
# get = _get_from_disk # 初回のみローダーを実行
#
 
# In Ruby
 
require 'YAML'
Config = lambda{
  p "this should be printed only once if cached"
  data = File.open('config.yml')
  config = YAML.load(data)
}.call
 
p Config
p Config
 
# Very similar Temporary Scoping in Javascript
# config = function(){
# //logic
# }()