ruby on rails - How to append items to an array -


i have following:

myobject = {   id: user.id,   email: user.email, } 

i need add values so:

if current_user && current_user.id == user.id   myobject << {     notification_email: user.notification_email,     notification_email2: user.notification_email2   } end 

the code above raises error.

what's right way optionally append values object?

error

undefined method `<<' # did mean? <

perhaps want hash#merge.

myobject.merge(   notification_email: user.notification_email,   notification_email2: user.notification_email2 ) 

if want side effects, use banged version.

myobject.merge!(   notification_email: user.notification_email,   notification_email2: user.notification_email2 ) 

Comments

Popular posts from this blog

javascript - generate date range base on integers -

PHP and MySQL WP -