Home add key in hash based on condition
Reply: 0

add key in hash based on condition

user523 Published in May 22, 2018, 4:36 am

I have following method

def some_method
   ...do something here...

    @customer_info = {
      a: a,
      b: b

I want to add key c in @customer_info if variable customer is true so something like,

@customer_info = {
  a: a,
  b: b,
  c: something if customer is true

tried to do something like this but no luck

@customer_info.merge(customer.present? {c: something} : {})
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305615 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO