Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

psych does not process hash map with symbol #76

Closed
mcr opened this Issue · 3 comments

2 participants

@mcr
mcr commented

see: plataformatec/devise#2013

I think the fault is psych, I think it should have a .to_s on the o.value at line 21 of psych-1.3.4/lib/psych/visitors/

@tenderlove
Owner

Sorry, I need more information before I can help with this.

@mcr
mcr commented

Hi, I found the problem, as I indicated in the pullup request: a monkey patch to Hash::encode_with() tries to sort the keys, and the result is disaster when I run it against the test cases in psych. So, how can I sort the keys in my yaml? The major reason to do this is for system level testing of REST APIs...

@tenderlove
Owner

If you're emitting YAML and you need to sort the keys, it's best just to create a new hash with the sorted keys:

irb(main):001:0> require 'psych'
=> true
irb(main):002:0> x = { 'b' => '1', 'a' => '2' }
=> {"b"=>"1", "a"=>"2"}
irb(main):003:0> puts Psych.dump x
---
b: '1'
a: '2'
=> nil
irb(main):004:0> y = Hash[x.sort_by { |k,| k }]
=> {"a"=>"2", "b"=>"1"}
irb(main):005:0> puts Psych.dump y
---
a: '2'
b: '1'
=> nil
irb(main):006:0>
@tenderlove tenderlove closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.