Assigning a variable based on existence of other variables in ruby 1.9 -
i got job fix webistrano installation , stuck in situation have receipt wherein following assignment broke after update ruby 1.8 ruby 1.9.3
if defined? var_one != nil var_to_be_used = var_one else $logger.info(var_one) var_to_be_used = var_two end i have made sure (by adding above log-entries) var_one , var_two hold expected values. example when expect var_one hold value got following log:
** value in var_one
*** undefined local variable or method `var_two' #<capistrano::configuration::namespaces::namespace:0x000000032a6040>
the first case never reached. script goes else case - when var_one holds string.
how can fix it?
i solved with
var_to_be_used ||= var_one rescue var_to_be_used ||= var_two rescue nil accessing via var_one.nil? caused undefined local variable or method 'var_one' again.
Comments
Post a Comment