Class: Storage
- Inherits:
-
Object
- Object
- Storage
- Defined in:
- lib/universum/storage.rb
Overview
keep track of contract state
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ Storage
constructor
A new instance of Storage.
-
#method_missing(m, *args, &block) ⇒ Object
todo/future: in the future auto-add getter/setter methods on setup do NOT use method_missing!!!.
Constructor Details
#initialize ⇒ Storage
Returns a new instance of Storage.
8 9 10 |
# File 'lib/universum/storage.rb', line 8 def initialize @data = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
todo/future: in the future auto-add getter/setter methods on setup
do NOT use method_missing!!!
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/universum/storage.rb', line 27 def method_missing( m, *args, &block ) puts "Storage#method_missing( #{m.inspect}), #{args.inspect} )" ## todo: add support ? for bool ## elsif m.end_with?('?') && args.empty? ## @storage[m] if m =~/\A[a-z][a-zA-Z0-9_]*=\z/ && args.size == 1 key = m[0...-1].to_sym ## note: cut-off trailing equal sign (=), use EXCLUSIVE (...) range and NOT INCLUSIVE (..) value = args[0] puts " SSTORE( #{key.inspect}, #{value.inspect} )" @data[key] = value elsif m =~/\A[a-z][a-zA-Z0-9_]*\z/ && args.empty? ## todo/fix: check for valid identifier key = m puts " SLOAD( #{key.inspect} )" @data[key] else super end end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 15 |
# File 'lib/universum/storage.rb', line 12 def [](key) puts " SLOAD( #{key.inspect} )" @data[key] end |
#[]=(key, value) ⇒ Object
17 18 19 20 |
# File 'lib/universum/storage.rb', line 17 def []=(key,value) puts " SSTORE( #{key.inspect}, #{value.inspect} )" @data[key] = value end |