lib/hash_object.rb
def add(model_object,*keys,&block)
        keys.each do |key|
          #if marked as optional skip if not present
          if key.to_s =~ /(^.+)\?$/
            key = $1.to_sym
            next unless model_object[key]
          end
          #special treatment of :id
          val = (key == :id ? model_object.id : model_object[key]) 
          self[key] = (block ? block.call(val) : val)
        end
        self
      end
#field with '?' suffix means optioanlly add depending on whether name present and non-null in source
#if block is given then apply to source[name] rather than returning just source[name]
field with '?' suffix means optioanlly add depending on whether name present and non-null in source
if block is given then apply to source[name] rather than returning just source[name]
field with ' ? ' suffix means optioanlly add depending on whether name present and non - null in source if block is given then apply to source [ name ] rather than returning just source [ name ]
def add(model_object,*keys,&block)
        keys.each do |key|
          if key.to_s =~ /(^.+)\?$/
            key = $1.to_sym
            next unless model_object[key]
          end
          val = (key == :id ? model_object.id : model_object[key]) 
          self[key] = (block ? block.call(val) : val)
        end
        self
      end
def add ( model_object , * keys , & block ) keys . each do | key | if key . to_s =~ / (^.+) \? $ / key = $1 . to_sym next unless model_object [ key ] end val = ( key == :id ? model_object . id : model_object [ key ] ) self [ key ] = ( block ? block . call ( val ) : val ) end self end
field with '?'
field with ' ? '
#if marked as optional skip if not present #special treatment of :id
model_object
keys
block