Skip to main content
3 of 6
deleted 8 characters in body
tokland
  • 11.1k
  • 1
  • 20
  • 25

Try to write the code as declarative as you possible can (that usually means in functional style):

def transform
  special_values = {"1" => true, "0" => false}
  Hash[preferences.map { |k, v| [k.to_sym, special_values.fetch(v, v)] }]
end

However, since I don't like Hash[...] and prefer Enumerable#mash, I'd really write preferences.mash { |k, v| [k.to_sym, special_values.fetch(v, v)] }.

tokland
  • 11.1k
  • 1
  • 20
  • 25