[Nitro] CascadingOpenObject

TRANS transfire at gmail.com
Mon Apr 3 13:31:59 EDT 2006


new class for facets. It the same as openobject but when a hash is the
resulting lookup value  it gets converted to another
"CascadingOpenObject". Anyone got a better name? (code below)

Btw I also added an interesting feature to both OpenObject and this
new class. If @parent is set then a value not found in the current
object will be searched for in the parent. This allows for inherited
values.


class CascadingOpenObject < OpenObject

  def method_missing( sym, *args )
    type = sym.to_s[-1,1]
    name = sym.to_s.gsub(/[=!?]$/, '').to_sym
    if type == '='
      @table[name] = args[0]
    elsif type == '!' and args.size > 0
      @table[name] = args[0]
      self
    else
      if @table.key?(name)
        if Hash === @table[name]
          self.__class__.new( @table[name] )
        else
          @table[name]
        end
      elsif @parent
        @parent.__send__(name)
      else
        nil
        #  Kernel.null #@table[name] = instance.class.new
      end
    end
  end

end




More information about the Nitro-general mailing list