You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IMHO, literals should be allowed in case statements. They were disallowed in 56fa5fc.
Consider a case statement that is conditional on two variables. For example, here is a method that geocodes an address, latitude/longitude pair, or US zip code, depending on the number of arguments specified and their type.
defextract_location(args)case[args.size,args.first.class]when[1,Integer]{zip: to_zip_code(args[0])}when[1,String]place=Geocoder.search(args[0]).first{latitude: place.latitude,longitude: place.longitude}when[2,Numeric]{latitude: args[1],longitude: args[1]}elsefail(ArgumentError,'Must pass a latitude/longitude, zip or address')endend
Obviously, this code could be rewritten as as nested conditional statements but that would require duplicating the else clause. I think this a valid use case for a literal in a case statement.
The text was updated successfully, but these errors were encountered:
IMHO, literals should be allowed in
case
statements. They were disallowed in 56fa5fc.Consider a
case
statement that is conditional on two variables. For example, here is a method that geocodes an address, latitude/longitude pair, or US zip code, depending on the number of arguments specified and their type.Obviously, this code could be rewritten as as nested conditional statements but that would require duplicating the
else
clause. I think this a valid use case for a literal in acase
statement.The text was updated successfully, but these errors were encountered: