Class: Bocuse::Value
- Inherits:
-
Object
- Object
- Bocuse::Value
- Defined in:
- lib/bocuse/value.rb
Overview
This is a value object that by default starts out life as not having decided what exactly it is.
On first adding another object, it assumes an internal form.
It will complain if its internal form does not correspond to the assumed external one, ie. when you want to << something, but it has already assumed the internal form of a hash (<< does not exist on a hash).
Defined Under Namespace
Modules: Empty
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #[]=(key, value) ⇒ Object
- #dup ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(internal = Empty) ⇒ Value
constructor
A new instance of Value.
- #to_h ⇒ Object
Constructor Details
Instance Method Details
#<<(element) ⇒ Object
29 30 31 32 |
# File 'lib/bocuse/value.rb', line 29 def << element @internal = [] if empty? @internal << element end |
#[]=(key, value) ⇒ Object
24 25 26 27 |
# File 'lib/bocuse/value.rb', line 24 def []= key, value @internal = {} if empty? @internal[key] = value end |
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/bocuse/value.rb', line 20 def empty? @internal && @internal.empty? end |
#to_h ⇒ Object
34 35 36 |
# File 'lib/bocuse/value.rb', line 34 def to_h @internal unless Empty == @internal end |