# 在Ruby中hash 到hash.key

``foo = {'bar'=>'baz'}` `

` `point = { x = 10, y = 20 } -- Create new table print(point["x"]) -- Prints 10 print(point.x) -- Has exactly the same meaning as line above` `

` `>> require 'ostruct' => [] >> foo = {'bar'=>'baz'} => {"bar"=>"baz"} >> foo_obj = OpenStruct.new foo => #<OpenStruct bar="baz"> >> foo_obj.bar => "baz" >>` `

` `class Hash def method_missing(method, *opts) m = method.to_s if self.has_key?(m) return self[m] elsif self.has_key?(m.to_sym) return self[m.to_sym] end super end end` `

` `x = { 'test' => 'aValue', :test => 'bar'} x.test # => 'aValue'` `

` `class Hash def method_missing(n) self[n.to_s] end end` `

` `a={'foo'=>5, 'goo'=>6} def a.method_missing(n) self[n.to_s] end` `

HashDot允许使用点符号语法，同时仍然解决有关由@avdi处理的NoMethodErrors问题。 它比使用OpenStruct创build的对象更快，更易于穿越。

` `require 'hash_dot' a = {b: {c: {d: 1}}}.to_dot abcd => 1 require 'open_struct' os = OpenStruct.new(a) os.b => {c: {d: 1}} os.bcd => NoMethodError` `

` `a.non_method => NoMethodError` `
{"ft_lang_label":"__label__zh","ft_lang_prob":0.8053941,"math_prob":0.92489165,"size":1753,"snap":"2020-45-2020-50","text_gpt3_token_len":940,"char_repetition_ratio":0.09090909,"word_repetition_ratio":0.0,"special_character_ratio":0.27210495,"punctuation_ratio":0.14102565,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98817146,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-03T16:18:55Z\",\"WARC-Record-ID\":\"<urn:uuid:f4409dae-6f95-419a-b748-8e9b9272f930>\",\"Content-Length\":\"19562\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:95d1ed48-6d37-45eb-aa8f-e3f63a52c3b3>\",\"WARC-Concurrent-To\":\"<urn:uuid:e141462c-d286-47ab-9b00-50a5801d868f>\",\"WARC-IP-Address\":\"174.138.186.11\",\"WARC-Target-URI\":\"http://www.dovov.com/rubyhash-hash-key.html\",\"WARC-Payload-Digest\":\"sha1:BF3DBV2VDH3IUE5PKYIEVBSRKOUZHBIO\",\"WARC-Block-Digest\":\"sha1:JLBE7T2ECAP7ZYDR52YICYVCFIT75N4A\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141729522.82_warc_CC-MAIN-20201203155433-20201203185433-00310.warc.gz\"}"}