J
-j b-
I am used to using the following shortcut:
value = ARGV.shift or usage
where usage is a method.
However, I recently ran into a situation where the following did not
work (as expected, anyway):
$user_type = ARGV.shift or usage
$user_map = ARGV.shift or DEFAULT_MAP
DEFAULT_MAP is just a string constant. When I tried to access $user_map
later I was surprised to find that it was nil when no argument was
provided. If I changed things to:
$user_type = ARGV.shift or usage
$user_map = (ARGV.shift or DEFAULT_MAP)
I got behavior I expected ($user_map was assigned DEFAULT_MAP).
Why the two types of behavior based (as far as I can tell) on the type
of the second parameter to 'or'?
value = ARGV.shift or usage
where usage is a method.
However, I recently ran into a situation where the following did not
work (as expected, anyway):
$user_type = ARGV.shift or usage
$user_map = ARGV.shift or DEFAULT_MAP
DEFAULT_MAP is just a string constant. When I tried to access $user_map
later I was surprised to find that it was nil when no argument was
provided. If I changed things to:
$user_type = ARGV.shift or usage
$user_map = (ARGV.shift or DEFAULT_MAP)
I got behavior I expected ($user_map was assigned DEFAULT_MAP).
Why the two types of behavior based (as far as I can tell) on the type
of the second parameter to 'or'?