in ruby, how do you make this nested hash work?
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
You can assign nil to it.
@settings = {
:tab1 => {
:name => {
:required => true
},
:description => nil
}
}
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
}
]
}
精彩评论