Cannot use method .to_h

I cannot use method .to_h even though my ruby version is 2.4

Strange! Have you tried just testing the to_h method in pry? Maybe it has something to do with how you are running the specs.

So I copied the code into different file named “test.rb” and run that using “ruby test.rb”, and it worked. However, it still does not work when I use gem to test it.