class Mustache::Context

def find(obj, key, default = nil)

Returns the value of key in obj if it is found and default otherwise.

key is not found.
default - An optional default value, to return if the
key - The key whose value you want.
obj - The object to perform the lookup on.

invokes that method. You get the idea.
If it's an object that responds to the key as a method call,
appropriate. If the object is a hash, does a simple hash lookup.
Finds a key in an object, using whatever method is most
def find(obj, key, default = nil)
  hash = obj.respond_to?(:has_key?)
  if hash && obj.has_key?(key)
    obj[key]
  elsif hash && obj.has_key?(key.to_s)
    obj[key.to_s]
  elsif !hash && obj.respond_to?(key)
    meth = obj.method(key)
    if meth.arity == 1
      meth.to_proc
    else
      meth[]
    end
  else
    default
  end
end