查看网站首页
查看网站首页
查看 sitemap.xml
✏️ 正在编辑: new-c.yaml
路径:
/opt/alt/ruby18/share/ri/1.8/system/Hash/new-c.yaml
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
--- !ruby/object:RI::MethodDescription aliases: [] block_params: comment: - !ruby/struct:SM::Flow::P body: Returns a new, empty hash. If this hash is subsequently accessed by a key that doesn't correspond to a hash entry, the value returned depends on the style of <tt>new</tt> used to create the hash. In the first form, the access returns <tt>nil</tt>. If <em>obj</em> is specified, this single object will be used for all <em>default values</em>. If a block is specified, it will be called with the hash object and the key, and should return the default value. It is the block's responsibility to store the value in the hash if required. - !ruby/struct:SM::Flow::VERB body: " h = Hash.new("Go Fish")\n h["a"] = 100\n h["b"] = 200\n h["a"] #=> 100\n h["c"] #=> "Go Fish"\n # The following alters the single default object\n h["c"].upcase! #=> "GO FISH"\n h["d"] #=> "GO FISH"\n h.keys #=> ["a", "b"]\n\n # While this creates a new default object each time\n h = Hash.new { |hash, key| hash[key] = "Go Fish: #{key}" }\n h["c"] #=> "Go Fish: c"\n h["c"].upcase! #=> "GO FISH: C"\n h["d"] #=> "Go Fish: d"\n h.keys #=> ["c", "d"]\n" full_name: Hash::new is_singleton: true name: new params: | Hash.new => hash Hash.new(obj) => aHash Hash.new {|hash, key| block } => aHash visibility: public
💾 保存文件
← 返回文件管理器