is there a better why how can I refactor this code, making sure that values in a Hash
are typecasted to true/false
if their value is '1'
or '0'
while leaving unaltered the rest?
I'm using Ruby 2.0.0 if that matters, and I'd like to improve this code.
def transform
hsh = {}
preferences.each do |k, v|
v = case v
when '1'
true
when '0'
false
else
v
end
hsh[k.to_sym] = v
end
hsh
end