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

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -