class MemoRack::Locals
Public Class Methods
define_key(name, &block)
click to toggle source
キーにメソッドを登録する
# File lib/memorack/locals.rb, line 63 def self.define_key(name, &block) define_method(value_method(name), &block) end
value_method(name)
click to toggle source
値を取出すメソッド名
# File lib/memorack/locals.rb, line 58 def self.value_method(name) :"value_#{name}" end
Public Instance Methods
[](key)
click to toggle source
値を取出す
Calls superclass method
# File lib/memorack/locals.rb, line 8 def [](key) return super if super_has_key?(key) return context[key].call(self, key) if context[key] return value(key) if value_method?(key) super end
context()
click to toggle source
コールバック登録用のハッシュ
# File lib/memorack/locals.rb, line 33 def context @context ||= {} end
context=(value)
click to toggle source
コールバック登録用のハッシュを代入する(merge用)
# File lib/memorack/locals.rb, line 38 def context=(value) @context = value end
define_key(name, &block)
click to toggle source
キーにコールバックを登録する
# File lib/memorack/locals.rb, line 43 def define_key(name, &block) context[name] = block end
has_key?(key)
click to toggle source
キーがあるか?
Calls superclass method
# File lib/memorack/locals.rb, line 17 def has_key?(key) return true if super return true if context.has_key?(key) return true if value_method?(key) false end
Also aliased as: super_has_key?
merge(hash)
click to toggle source
マージ
Calls superclass method
# File lib/memorack/locals.rb, line 26 def merge(hash) new_hash = super new_hash.context = context.dup new_hash end
value(name)
click to toggle source
値をメソッドから取出す
# File lib/memorack/locals.rb, line 53 def value(name) send(Locals.value_method(name), name) end
value_method?(name)
click to toggle source
値を取出すメソッドがあるか?
# File lib/memorack/locals.rb, line 48 def value_method?(name) respond_to?(Locals.value_method(name)) end