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

Code should be as declarative as possible (that usually means in functional styleusually 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)] }.

Code should be as declarative as possible (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, 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)] }.

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)] }.

deleted 4 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25

Try to write the codeCode should be 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[...] is very ugly and I prefer thea more OOP approach with Enumerable#mash, so I'd really write preferences.mash { |k, v| [k.to_sym, special_values.fetch(v, v)] }.

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 the more OOP Enumerable#mash, I'd really write preferences.mash { |k, v| [k.to_sym, special_values.fetch(v, v)] }.

Code should be as declarative as possible (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, 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)] }.

added 13 characters in body
Source Link
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 the more OOP Enumerable#mash, I'd really write preferences.mash { |k, v| [k.to_sym, special_values.fetch(v, v)] }.

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)] }.

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 the more OOP Enumerable#mash, I'd really write preferences.mash { |k, v| [k.to_sym, special_values.fetch(v, v)] }.

deleted 8 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25
Loading
added 234 characters in body
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25
Loading
Source Link
tokland
  • 11.1k
  • 1
  • 20
  • 25
Loading