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

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -