I have the following function in payment.rb
def self.create_customer_with_card arg
customer_list = Curl.get("#{BaseURL}/customer") do |curl|
curl.headers["Authorization"] = authorization_header
curl.headers['Content-Type'] = 'application/json'
end
customer = Curl.get("#{BaseURL}/customer/660391") do |curl|
curl.headers["Authorization"] = authorization_header
curl.headers['Content-Type'] = 'application/json'
end
byebug
end
I placed the byebug at the end of function. when no matter either I check customer_list or customer it gives me result of customer. while if I try them individually results are okay. But keeping both in same function assigns the output of second function to both variables. I'm using gem 'curb', '~> 0.9.4' for curl. any idea?
When you have a Ruby method of the form:
The return value of this method is always the value assigned to the local variable
band any value assigned to local variableais thrown away. Remember that local variables only exist within the scope of your block unless closures are involved. Outside of that scope any values they contain are thrown away unless otherwise retained.If you want to return both values, just do this:
Then you call it like this:
Though
argis not used, so until it is you should remove it.Once in this form it becomes fairly obvious a more minimal form is:
Where that uses
mapto convert two paths to two results.