When I do the following:
h = { "a": 123 }
Ruby / Rails automatically converts the key to a character.
h[:a] # => 123 h["a"] # => nil
How can I prevent this behavior? I created a hash with a string key and would like to save it that way without naming it Hash#stringify_keys.
Hash#stringify_keys
Use rocket hash syntax:
h = { "a" => 123 } #=> {"a"=>123} h['a'] #=> 123
Try
h = { "a" => 123 }
Colon will make your key a symbol.
hashrocket :
:
h = { "a" => 123 } #=> {"a"=>123}
/,
. . :
:'foo-bar'.class # => Symbol
, , .
, " :foo / bar". , String#to_sym. , :
:foo
bar
String#to_sym
{'foo-bar'.to_sym => 42, :this_now_needs_rocket_notation => 'baz'}
, " " / -. , , , .
Source: https://habr.com/ru/post/1658414/More articles:Associate a custom auth provider with Firebase - androidTypeError: невозможно прочитать свойство Selector-Matcher - angularProtractor "Bad Inspector Message" - angularjshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1658412/facebook-oauth-access-token-response-in-json&usg=ALkJrhhfWQbHTr90OSLWcDLKKnk7QStuywОбновление с Angular 2.0.0 до 2.4.0 - Невозможно прочитать свойство SelectorMatcher - angularUpdate from Angular from 2.2.3 to 2.4.0 - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1658416/what-causes-the-module-resolves-to-a-non-module-entity-and-cannot-be-imported-using-this-construct-error-in-typescript&usg=ALkJrhgCkD8859vhJersaWDi0zON4zo3UAPushbase Firebase notification not working in background and application is inactive in swift 3.0 - iosAre there any Android phones that support extended APDUs? - androidMake JS functions more efficient and dynamic - javascriptAll Articles