Class: HashWrapper

Inherits:
Object show all
Includes:
FromHash
Defined in:
lib/formula_eval/wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &b) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/formula_eval/wrapper.rb', line 18

def method_missing(sym,*args,&b)
  if obj.keys.include?(sym.to_s)
    self[sym.to_s]
  else
    super
  end
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



16
17
18
# File 'lib/formula_eval/wrapper.rb', line 16

def hash
  @hash
end

Instance Method Details

#[](x) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/formula_eval/wrapper.rb', line 25

def [](x)
  raise 'dot_set' if x.to_s == 'dot_set'
  res = hash[x.to_s]
  res = nil if res.blank?
  # raise "nil key #{x}" unless res
  res.to_wrapped
end

#[]=(k, v) ⇒ Object



32
33
34
# File 'lib/formula_eval/wrapper.rb', line 32

def []=(k,v)
  obj[k.to_s] = v
end

#delete(k) ⇒ Object



45
46
47
# File 'lib/formula_eval/wrapper.rb', line 45

def delete(k)
  obj.delete(k)
end

#keysObject



52
53
54
# File 'lib/formula_eval/wrapper.rb', line 52

def keys
  obj.keys
end

#kind_of?(x) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/formula_eval/wrapper.rb', line 48

def kind_of?(x)
  return true if x == Hash
  super
end

#objObject



35
# File 'lib/formula_eval/wrapper.rb', line 35

def obj; hash; end

#respond_to?(sym) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/formula_eval/wrapper.rb', line 42

def respond_to?(sym)
  obj.keys.include?(sym.to_s)
end

#to_unwrappedObject



39
40
41
# File 'lib/formula_eval/wrapper.rb', line 39

def to_unwrapped
  hash.to_unwrapped
end

#to_wrappedObject



36
37
38
# File 'lib/formula_eval/wrapper.rb', line 36

def to_wrapped
  self
end