ruby on rails - How can I change this from a local to instance variable? -
i have block of code:
if %w[ups fedex usps].include?(carrier.slug) send(carrier.slug).track(number) end
which replicates:
ups.track(number) fedex.track(number) usps.track(number)
but need that, instance variables:
@ups.track(number) @fedex.track(number) @usps.track(number)
what's equivalent?
if %w[ups fedex usps].include?(carrier.slug) var_name = "@#{carrier.slug}" instance_variable_get(var_name).track(number) end
by way, interpretation incorrect.
ups.track(number) fedex.track(number) usps.track(number)
these treated methods, not local variables. if there's no method ups
, code fail (even if there local var same name).
Comments
Post a Comment