1) I have a method
def self.createobj(api_key, amnt, commentstr, orderid, order_creation_date, orderfullfilmentdate)
.....
end
2) I want to create a error_str of all the parameters passed to this function …
2.1) Something like
errorstr = "api_key: " + api_key.to_s + " amnt: " + amnt.to_s + " commentstr: " + commentstr.to_s + " orderid: " + orderid.to_s + " order_creation_date: " + order_creation_date.to_s + " orderfullfilmentdate: " + orderfullfilmentdate.to_s
2.2) So I created another method
def self.get_params_str(a)
str = ""
a.each do |a|
str = str + a.to_s
end
return str
end
2.3) So I call this new method from createobj. Something like
def self.createobj(api_key, amnt, commentstr, orderid, order_creation_date, orderfullfilmentdate)
errorstr = get_params_str(args)
.....
end
3) But I get error undefined local variable or method `args’ for #. Shouldn’t args have all parameters?
Please advice.
argswould only contain the parameters if your method definition was something likedef self.createobj(*args). Without thatargsisn’t defined.You will need to manually pass all of the parameters to
get_params_str. You will need to pass them as an array, i.eget_params_str([api_key, amnt, commentstr, ...])unless you changeget_params_str‘s method signature todef self.get_params_str(*a)(which puts all of the parameters passed toget_params_strinto a single array`).