Can I put some form of If..End blocks inside of a hash definition?

Posted by Benjamin Manns on Stack Overflow See other posts from Stack Overflow or by Benjamin Manns
Published on 2010-04-06T01:53:38Z Indexed on 2010/04/06 2:03 UTC
Read the original article Hit count: 345

Filed under:
|
|

I am creating a web application to integrate with Chargify. I want to return a hash with customer_id set if the user has a customer associated with the account, and customer_attributes if a customer has to be created.

Is there any way that I could do this with an if..end block inside of the hash definition. For example, I would be wanting to do something like the following (does not work):

def subscription_params(product_id)
  {
    :product_id => product_id,
    if customer_id.nil?
      :customer_attributes => customer_params,
    else
      :customer_id => customer_id,
    end
    :credit_card_attributes => credit_card_params
  }
end

© Stack Overflow or respective owner

Related posts about ruby

Related posts about arrays