lib/musterb/evaluator.rb in musterb-0.0.1 vs lib/musterb/evaluator.rb in musterb-0.0.2

- old
+ new

@@ -2,11 +2,15 @@ def initialize(context) @context = context end def [](symbol) - @context[symbol] + return @context.value if symbol == "." + final_context = symbol.split(".").inject(@context) do |con, symbol| + new_context con[symbol], con + end + final_context.value end def block(symbol) value = self[symbol] return if is_falsy? value @@ -36,15 +40,17 @@ else !value end end - def new_context(value) + def new_context(value, old_context = @context) case value when Hash - HashExtractor.new(value, @context) + Musterb::HashExtractor.new(value, old_context) + when nil + Musterb::NullExtractor.new(old_context) else - ObjectExtractor.new(value, @context) + Musterb::ObjectExtractor.new(value, old_context) end end def old_context @context.parent \ No newline at end of file