Skip to content

Instantly share code, notes, and snippets.

@nbomberger
Forked from rmw/hash.rb
Created February 16, 2014 04:56
Show Gist options
  • Save nbomberger/9029466 to your computer and use it in GitHub Desktop.
Save nbomberger/9029466 to your computer and use it in GitHub Desktop.
class Hash
def with_sym_keys
self.inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo }
end
end
require 'spec_helper'
describe Hash do
describe "#with_sym_keys" do
it "should replace string keys with symbols" do
hash = { "a" => 1, "b" => 1 }
hash.with_sym_keys.should == { :a => 1, :b => 1 }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment