Skip to main content
6 of 6
added 73 characters in body
tokland
  • 11.1k
  • 1
  • 20
  • 25

Code should be as declarative as possible (usually by using 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, Hash[...] is very ugly and I prefer a more OOP approach with Enumerable#mash, so I'd really write preferences.mash { |k, v| [k.to_sym, special_values.fetch(v, v)] }.

tokland
  • 11.1k
  • 1
  • 20
  • 25