📜  红宝石 |哈希检查()函数

📅  最后修改于: 2022-05-13 01:55:29.670000             🧑  作者: Mango

红宝石 |哈希检查()函数

Hash#inspect()是一个 Hash 类方法,它给出了 hash 的字符串表示。

示例 #1:

Ruby
# Ruby code for Hash.inspect() method
 
# declaring Hash value
a = {a:100, b:200}
 
# declaring Hash value
b = {a:100, c:300, b:200}
 
# declaring Hash value
c = {a:100}
 
 
# inspect Value
puts "Hash a inspect form : #{a.inspect()}\n\n"
 
puts "Hash b inspect form : #{b.inspect()}\n\n"
 
puts "Hash c inspect form : #{c.inspect()}\n\n"


Ruby
# Ruby code for Hash.inspect() method
 
# declaring Hash value
a = { "a" => 100, "b" => 200 }
 
# declaring Hash value
b = {"a" => 100}
 
# declaring Hash value
c = {"a" => 100, "c" => 300, "b" => 200}
 
 
# inspect Value
puts "Hash a inspect form : #{a.inspect()}\n\n"
 
puts "Hash b inspect form : #{b.inspect()}\n\n"
 
puts "Hash c inspect form : #{c.inspect()}\n\n"


输出 :

Hash a inspect form : {:a=>100, :b=>200}

Hash b inspect form : {:a=>100, :c=>300, :b=>200}

Hash c inspect form : {:a=>100}

示例 #2:

红宝石

# Ruby code for Hash.inspect() method
 
# declaring Hash value
a = { "a" => 100, "b" => 200 }
 
# declaring Hash value
b = {"a" => 100}
 
# declaring Hash value
c = {"a" => 100, "c" => 300, "b" => 200}
 
 
# inspect Value
puts "Hash a inspect form : #{a.inspect()}\n\n"
 
puts "Hash b inspect form : #{b.inspect()}\n\n"
 
puts "Hash c inspect form : #{c.inspect()}\n\n"

输出 :

Hash a inspect form : {"a"=>100, "b"=>200}

Hash b inspect form : {"a"=>100}

Hash c inspect form : {"a"=>100, "c"=>300, "b"=>200}