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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -