Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you create a hash in a ruby function that can be passed as an argument to another function?
    primarykey
    data
    text
    <h2>Ruby Stripe</h2> <p>I'm trying to interface with the Ruby Stripe library, specifically with the subscription_update function as documented here: <a href="https://stripe.com/docs/api#update_subscription" rel="nofollow">https://stripe.com/docs/api#update_subscription</a></p> <p>This is what the syntax looks like:</p> <pre><code>c = Stripe::Customer.retrieve("cus_2BWdBuTAE3HboP") c.update_subscription(:plan =&gt; "basic", :prorate =&gt; true) </code></pre> <h2>Implementing Rails Model</h2> <p>I'm implementing a rails model that can interface with the ruby library. Since this api will update my subscription with nil values (that will over ride the defaults), I need a function that will crawl the writable attributes and create an array of only the attributes that are not nil that I can pass to this update_subscription function.</p> <p>Here's what I have now:</p> <pre><code> def get_non_nil_update_attributes attributes = Array.new([ :plan, :trial_end, :quantity, :coupon, :prorate ]) return_attributes = {} attributes.each do |attribute| if !self.send( attribute ).nil? return_attributes[attribute] = self.send( attribute) end end return return_attributes end </code></pre> <p>I would like to just call this:</p> <p><code>c.update_subscription( mymodel.get_non_nil_update_attributes )</code> </p> <p>But I get an error that I'm not passing in the plan param. At the console my output if this function is:</p> <pre><code>[{:plan=&gt;"7"}, {:trial_end=&gt;"bla"}] </code></pre> <p>I know this is a simply ruby question but how do I make this output just <code>:plan =&gt; "7", :trial_end =&gt; "bla"</code> to pass into my function?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload