Search code examples
rubyactivesupport

undefined method `symbolize_keys' after requiring active support.


I am trying to symbolize the keys of a hash in a non rails project. I can see the symbolize_keys method is part of Active Support so I imported the library but it still doesn't work.

Here is an example of it failing

2.4.2 :001 > require 'active_support'
 => true 
2.4.2 :002 > {'test' => 'test'}.symbolize_keys
NoMethodError: undefined method `symbolize_keys' for {"test"=>"test"}:Hash

Expected output

{test: "test"}

Solution

  • You should require 'active_support/all' if you want active support core extensions also required:

    2.3.4 :002 > require 'active_support/all'
     => true 
    2.3.4 :003 > {'test' => 'test'}.symbolize_keys
     => {:test=>"test"}