Skip to content

Instantly share code, notes, and snippets.

@frankie-loves-jesus
Last active August 29, 2015 14:05
Show Gist options
  • Save frankie-loves-jesus/e0cbc5ba3584c722596f to your computer and use it in GitHub Desktop.
Save frankie-loves-jesus/e0cbc5ba3584c722596f to your computer and use it in GitHub Desktop.

Simplify

Can this:

def self.prettify(x)
  x.is_a?(Hash) ? Hash[ x.map{ |k, v| [k.underscore, prettify(v)]} ] : x
  x.is_a?(Array) ? x.map{ |v| prettify(v) } : x
end

be written like this?

def self.prettify(x)
  if x.is_a?(Hash)
    Hash[
      x.map{ |k, v| [k.underscore, prettify(v)] }
    ]
  elsif x.is_a?(Array)
    x.map{ |v| prettify(v) }
  else
    x
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment