I am wondering if it is possible, given that these global variables exist and are accessed by other functions, to tell a function to use one variable or another without re-writing huge chunks of code. I have to use global variables because of my limitations with calabash passing variables around (correct me if I'm wrong). I want to be able to call one function that can grab information and stuff it into one of several global variables. Something hopefully like this:
def add_five(my_var)
if my_var == "my_cats"
use $my_cats for my_var_nickname
elsif my_var == "my_dogs"
use $my_dogs for my_var_nickname
elsif my_var == "my_birds"
use $my_birds for my_var_nickname
end
my_var_nickname = my_var_nickname + 5
end
$my_cats = 2
$my_dogs = 3
$my_birds = 3
add_five("my_cats")
$my_cats = 7
$my_dogs = 3
$my_birds = 3
Thanks for the help!
b = ((stuffy == "foo") ? $A : $B)and then useb, but you should try to avoid using global variables.$) like that has significant code smell.