feat: Add Ruby code - chapter "Hashing" (#1276)

* feat: add ruby code - chapter hashing

* feat: add ruby code blocks - chapter hashing

* fix: comments
This commit is contained in:
khoaxuantu
2024-04-15 15:20:26 +07:00
committed by GitHub
parent 2b11639103
commit be9931c8a1
9 changed files with 618 additions and 30 deletions

View File

@@ -299,7 +299,7 @@ $$
```rust title="built_in_hash.rs"
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
let num = 3;
let mut num_hasher = DefaultHasher::new();
num.hash(&mut num_hasher);
@@ -374,7 +374,29 @@ $$
=== "Ruby"
```ruby title="built_in_hash.rb"
num = 3
hash_num = num.hash
# 整数 3 的哈希值为 -4385856518450339636
bol = true
hash_bol = bol.hash
# 布尔量 true 的哈希值为 -1617938112149317027
dec = 3.14159
hash_dec = dec.hash
# 小数 3.14159 的哈希值为 -1479186995943067893
str = "Hello 算法"
hash_str = str.hash
# 字符串“Hello 算法”的哈希值为 -4075943250025831763
tup = [12836, '小哈']
hash_tup = tup.hash
# 元组 (12836, '小哈') 的哈希值为 1999544809202288822
obj = ListNode.new(0)
hash_obj = obj.hash
# 节点对象 #<ListNode:0x000078133140ab70> 的哈希值为 4302940560806366381
```
=== "Zig"