Class: Bindings::CacheBinding
- Inherits:
-
Object
- Object
- Bindings::CacheBinding
- Includes:
- Binding
- Defined in:
- lib/binding.rb
Overview
An implementation of Bindings::Binding that caches values once they’ve been retrieved.
Instance Method Summary collapse
-
#get_as_bytes(key) ⇒ String?
Returns the contents of a binding entry in its raw bytes form.
-
#initialize(delegate) ⇒ CacheBinding
constructor
Creates a new instance.
-
#name ⇒ String
Returns the name of the binding.
Methods included from Binding
Constructor Details
#initialize(delegate) ⇒ CacheBinding
Creates a new instance.
88 89 90 91 |
# File 'lib/binding.rb', line 88 def initialize(delegate) @delegate = delegate @cache = {} end |
Instance Method Details
#get_as_bytes(key) ⇒ String?
Returns the contents of a binding entry in its raw bytes form.
98 99 100 101 102 103 104 105 |
# File 'lib/binding.rb', line 98 def get_as_bytes(key) return @cache[key] if @cache.key?(key) v = @delegate.get_as_bytes(key) @cache[key] = v unless v.nil? v end |
#name ⇒ String
Returns the name of the binding
110 111 112 |
# File 'lib/binding.rb', line 110 def name @delegate.name end |