0

我有以下哈希:

EMAIL_PWD_HASH = Hash.new
EMAIL_PWD_HASH[ "email" ] =  { "label" => EMAIL_STR, "type" => "email_field" }
EMAIL_PWD_HASH[ "password" ] = { "label" => PWD_STR, "type" => "password_field" }

和以下哈希:

NEW_USER_HASH = Hash.new
NEW_USER_HASH[ "first" ] = { "label" => FIRST_STR, "type" => "text_field" }
NEW_USER_HASH[ "last" ] =  { "label" => LAST_STR, "type" => "text_field" }

NEW_USER_HASH[ "title" ] =  { "label" => TITLE_STR, "type" => "text_field" }
NEW_USER_HASH[ "bio" ] =  { "label" => BIO_STR, "type" => "text_field" }

我想在最后一个生物之前和之前将电子邮件和密码添加到 NEW_USER_HASH。添加 EMAIL_PWD_HASH 的语法是什么(顺序很重要)?

4

2 回答 2

1
NEW_USER_HASH.merge!(EMAIL_PAD_HASH)

另请注意,ruby 中的哈希值没有排序。

于 2012-05-14T22:04:38.887 回答
0

我不知道该怎么做你问的,我怀疑这是可能的,但这是一种快速而肮脏的方法来做你需要的事情:

NEW_USER_HASH['email']    = EMAIL_PWD_HASH['email']
NEW_USER_HASH['password'] = EMAIL_PWD_HASH['password']
NEW_USER_HASH['bio']      = NEW_USER_HASH.delete('bio')  # deletes bio and reinsert in the end

email正如你所问的,现在password是 afterlast和 before 。bio:)

于 2012-05-14T23:29:44.810 回答