File tree Expand file tree Collapse file tree 3 files changed +12
-6
lines changed
activesupport/lib/active_support Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,13 @@ class Hash
8
8
# hash.stringify_keys
9
9
# # => {"name"=>"Rob", "age"=>"28"}
10
10
def stringify_keys
11
- transform_keys ( & : to_s)
11
+ transform_keys { | k | Symbol === k ? k . name : k . to_s }
12
12
end
13
13
14
14
# Destructively converts all keys to strings. Same as
15
15
# +stringify_keys+, but modifies +self+.
16
16
def stringify_keys!
17
- transform_keys! ( & : to_s)
17
+ transform_keys! { | k | Symbol === k ? k . name : k . to_s }
18
18
end
19
19
20
20
# Returns a new hash with all keys converted to symbols, as long as
@@ -82,14 +82,14 @@ def deep_transform_keys!(&block)
82
82
# hash.deep_stringify_keys
83
83
# # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
84
84
def deep_stringify_keys
85
- deep_transform_keys ( & : to_s)
85
+ deep_transform_keys { | k | Symbol === k ? k . name : k . to_s }
86
86
end
87
87
88
88
# Destructively converts all keys to strings.
89
89
# This includes the keys from the root hash and from all
90
90
# nested hashes and arrays.
91
91
def deep_stringify_keys!
92
- deep_transform_keys! ( & : to_s)
92
+ deep_transform_keys! { | k | Symbol === k ? k . name : k . to_s }
93
93
end
94
94
95
95
# Returns a new hash with all keys converted to symbols, as long as
Original file line number Diff line number Diff line change @@ -393,7 +393,7 @@ def to_proc
393
393
394
394
private
395
395
def convert_key ( key )
396
- key . kind_of? ( Symbol ) ? key . name : key
396
+ Symbol === key ? key . name : key
397
397
end
398
398
399
399
def convert_value ( value , conversion : nil )
Original file line number Diff line number Diff line change @@ -76,7 +76,13 @@ def jsonify(value)
76
76
when Hash
77
77
result = { }
78
78
value . each do |k , v |
79
- k = k . to_s unless String === k
79
+ unless String === k
80
+ k = if Symbol === k
81
+ k . name
82
+ else
83
+ k . to_s
84
+ end
85
+ end
80
86
result [ k ] = jsonify ( v )
81
87
end
82
88
result
You can’t perform that action at this time.
0 commit comments