views:

94

answers:

2

this one creates an error:

  @settings = { 
    :tab1 => {
      :name => {
        :required => true
      },
      :description
   }
  }

need to change :descrpition to :description => {}, but i don't have any values for :description so i want it to remain as is (without the empty => {})

Would you show me the best way to handle this kind of situation?

thanks in advance

+6  A: 

You can assign nil to it.

  @settings = { 
    :tab1 => {
      :name => {
        :required => true
      },
      :description => nil
   }
  }
Salil
+1  A: 

Ruby's Hash prior to 1.9 is not ordered, and even afterwards it's a bit clumsy, as AFAIK you can't reorder items etc., so if you also want to preserve the order of the elements, you may consider using array instead of hash:

@settings = {
  :tab1 => [
    {
      :field => :name,
      :required => true
    },
    {
      :field => :description
    }
  ] 
}
Mladen Jablanović