class Mustache::Context

Public Instance Methods

[](*args)

NOTE: :alias_method has to go after the re-definition of :fetch or else it uses the original :fetch method/definition.

Alias for: fetch
fetch(*args) click to toggle source
# File lib/www_app/TO.rb, line 51
def fetch *args
  raise ContextMiss.new("Can't find: #{args.inspect}") if args.size != 2

  meth, key = args

  @stack.each { |frame|
    case
    when frame.is_a?(Hash) && meth == :coll && !frame.has_key?(key)
      return false

    when frame.is_a?(Hash) && meth == :coll && frame.has_key?(key)
        target = frame[key]
        if target == true || target == false  || target == nil || target.is_a?(Array) || target.is_a?(Hash)
          return target
        end
        fail "Invalid value: #{key.inspect} (#{key.class})"

    when frame.is_a?(Hash) && frame.has_key?(key)
      return ::Escape_Escape_Escape.send(meth, frame[key])

    end
  }

  raise ContextMiss.new("Can't find .#{meth}(#{key.inspect})")
end
Also aliased as: []