class Storage
keep track of contract state
Public Class Methods
new()
click to toggle source
# File lib/universum/storage.rb, line 8 def initialize @data = {} end
Public Instance Methods
[](key)
click to toggle source
# File lib/universum/storage.rb, line 12 def [](key) puts " SLOAD( #{key.inspect} )" @data[key] end
[]=(key,value)
click to toggle source
# File lib/universum/storage.rb, line 17 def []=(key,value) puts " SSTORE( #{key.inspect}, #{value.inspect} )" @data[key] = value end
method_missing( m, *args, &block )
click to toggle source
todo/future: in the future auto-add getter/setter methods on setup
do NOT use method_missing!!!
Calls superclass method
# 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