Method: WLang::Scope#evaluate

Defined in:
lib/wlang/scope.rb

#evaluate(expr, dialect, *default, &bl) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wlang/scope.rb', line 48

def evaluate(expr, dialect, *default, &bl)
  expr = expr.to_s.strip
  unfound = lambda do
    if default.empty?
      bl ? bl.call(expr) : throw(:fail)
    else
      default.first
    end
  end
  if expr.index('.').nil?
    fetch(expr.to_sym, dialect, unfound)
  else
    keys = expr.split('.').map(&:to_sym)
    keys.inject(self){|scope,key|
      found = scope.fetch(key, dialect, unfound)
      Scope.coerce(found)
    }.subject
  end
end