Class: SeeingIsBelieving::HashStruct::Attr
- Inherits:
-
Object
- Object
- SeeingIsBelieving::HashStruct::Attr
- Defined in:
- lib/seeing_is_believing/hash_struct.rb
Overview
This could support dynamic attributes very easily ie they are calculated, but appear as a value (e.g. in to_hash) not sure how to deal with the fact that they could be assigned, though
Instance Method Summary collapse
-
#initialize(instance, value = nil, &block) ⇒ Attr
constructor
A new instance of Attr.
- #value ⇒ Object
Constructor Details
#initialize(instance, value = nil, &block) ⇒ Attr
Returns a new instance of Attr.
77 78 79 80 81 |
# File 'lib/seeing_is_believing/hash_struct.rb', line 77 def initialize(instance, value=nil, &block) @instance = instance @block = block if block @value = value unless block end |
Instance Method Details
#value ⇒ Object
82 83 84 85 |
# File 'lib/seeing_is_believing/hash_struct.rb', line 82 def value return @value if defined? @value @value = @block.call(@instance) end |