回答編集履歴
1
コメントに対して追記
test
CHANGED
@@ -11,3 +11,35 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
また、`foo.class == Hash`よりは、Hashのサブクラスのインスタンスでも良い`foo.is_a?(Hash)`の方が良いと思います。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
#コメントに対して追記。「そういうメソッド」の例。
|
18
|
+
|
19
|
+
```Ruby
|
20
|
+
|
21
|
+
def has_value?(item, key, value)
|
22
|
+
|
23
|
+
item.is_a?(Hash) && item.dig(*key) == value
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
# キーはシンボルとする
|
30
|
+
|
31
|
+
res = {error:
|
32
|
+
|
33
|
+
{title: "Unauthorized"}
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
if has_value?(res,[:error,:title],'Unauthorized')
|
38
|
+
|
39
|
+
~~
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
|