Skip to content

Instantly share code, notes, and snippets.

@3den
Last active December 22, 2015 09:59
Show Gist options
  • Select an option

  • Save 3den/6455996 to your computer and use it in GitHub Desktop.

Select an option

Save 3den/6455996 to your computer and use it in GitHub Desktop.
def hashfy(array)
array.size > 1 ? {array.shift => hashfy(array)} : array.shift
end
require "minitest/autorun"
describe "#hashfy" do
it "converts an array to a nested hash" do
hashfy([:animal, :dog]).must_equal({animal: :dog})
hashfy([:animal, :mammal, :dog]).must_equal({animal: {mammal: :dog}})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment