"Example_Value"} example["Example_Key"] ...">All geek questions in one placeIs there a way to access keys from values?If I print something like:example = {"Example_Key" => "Example_Value"} example["Example_Key"] the interpreter will return "Example_Value"what is the value. Is there a way to enter a value and get the key?+4ruby key hashDor-ron Jul 13 '14 at 7:50source share2 answersYes there is:example = {"Example_Key" => "Example_Value"} example.key "Example_Value" # => "Example_Key" Check out the documentation Hash#keyReturns the key for a given value.. If the valuenot found, returns nil.+3Arup rakshit Jul 13 '14 at 7:53source shareYou can create a hash that works differently:inverted = example.invert # => {"Example_Value"=>"Example_Key"} inverted["Example_Value"] # => "Example_Key" +1sawa Jul 13 '14 at 7:54source shareSource: https://habr.com/ru/post/1548234/More articles:Add intro for dynamically added elements - backbone.jsRails 4 shows the boot counter for the csv file and hides the counter after the download is complete - jqueryWhy take CMP ECX, ECX? - assemblyHow to put yiibooster textField inside /view/layout/main.php in Yii - phpflash protection: minimize database hits - pythonNutch 2.x does not crawl sites like flipkart and jabong - hbaseRecursion for the inductive process - rXcode - generate implementation shortcut - c ++iBeacon: Attempting to track more zones than we have room for - ibeaconhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1548239/how-to-prevent-other-classes-to-create-instance-of-one-class&usg=ALkJrhiyxJxPzvmc1iN7tjua5AkW08_qQgAll Articles
If I print something like:
example = {"Example_Key" => "Example_Value"} example["Example_Key"]
the interpreter will return "Example_Value"what is the value. Is there a way to enter a value and get the key?
"Example_Value"
Yes there is:
example = {"Example_Key" => "Example_Value"} example.key "Example_Value" # => "Example_Key"
Check out the documentation Hash#key
Hash#key
Returns the key for a given value.. If the valuenot found, returns nil.
nil
You can create a hash that works differently:
inverted = example.invert # => {"Example_Value"=>"Example_Key"} inverted["Example_Value"] # => "Example_Key"
Source: https://habr.com/ru/post/1548234/More articles:Add intro for dynamically added elements - backbone.jsRails 4 shows the boot counter for the csv file and hides the counter after the download is complete - jqueryWhy take CMP ECX, ECX? - assemblyHow to put yiibooster textField inside /view/layout/main.php in Yii - phpflash protection: minimize database hits - pythonNutch 2.x does not crawl sites like flipkart and jabong - hbaseRecursion for the inductive process - rXcode - generate implementation shortcut - c ++iBeacon: Attempting to track more zones than we have room for - ibeaconhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1548239/how-to-prevent-other-classes-to-create-instance-of-one-class&usg=ALkJrhiyxJxPzvmc1iN7tjua5AkW08_qQgAll Articles