Class: Liquid::Registers
- Inherits:
-
Object
- Object
- Liquid::Registers
- Defined in:
- lib/liquid/registers.rb
Constant Summary collapse
- UNDEFINED =
Object.new
Instance Attribute Summary collapse
-
#static ⇒ Object
readonly
Returns the value of attribute static.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #fetch(key, default = UNDEFINED, &block) ⇒ Object
-
#initialize(registers = {}) ⇒ Registers
constructor
A new instance of Registers.
- #key?(key) ⇒ Boolean
Constructor Details
Instance Attribute Details
#static ⇒ Object (readonly)
Returns the value of attribute static.
5 6 7 |
# File 'lib/liquid/registers.rb', line 5 def static @static end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/liquid/registers.rb', line 16 def [](key) if @changes.key?(key) @changes[key] else @static[key] end end |
#[]=(key, value) ⇒ Object
12 13 14 |
# File 'lib/liquid/registers.rb', line 12 def []=(key, value) @changes[key] = value end |
#delete(key) ⇒ Object
24 25 26 |
# File 'lib/liquid/registers.rb', line 24 def delete(key) @changes.delete(key) end |
#fetch(key, default = UNDEFINED, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/liquid/registers.rb', line 30 def fetch(key, default = UNDEFINED, &block) if @changes.key?(key) @changes.fetch(key) elsif default != UNDEFINED if block_given? @static.fetch(key, &block) else @static.fetch(key, default) end else @static.fetch(key, &block) end end |
#key?(key) ⇒ Boolean
44 45 46 |
# File 'lib/liquid/registers.rb', line 44 def key?(key) @changes.key?(key) || @static.key?(key) end |