This repository was archived by the owner on Mar 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ def [](key)
32
32
@values [ rkey ] if rkey
33
33
end
34
34
35
+ alias_method :get , :[]
36
+
35
37
# Add a key/value to the map.
36
38
def []=( key , value )
37
39
ObjectSpace . define_finalizer ( key , @reference_cleanup )
@@ -41,6 +43,8 @@ def []=(key, value)
41
43
end
42
44
end
43
45
46
+ alias_method :put , :[]=
47
+
44
48
# Remove the value associated with the key from the map.
45
49
def delete ( key )
46
50
rkey = ref_key ( key )
@@ -90,7 +94,7 @@ def merge!(other_hash)
90
94
91
95
# The number of entries in the map
92
96
def size
93
- @references_to_keys_map . count do |rkey , ref |
97
+ @references_to_keys_map . count do |_ , ref |
94
98
ref . object
95
99
end
96
100
end
@@ -99,7 +103,11 @@ def size
99
103
100
104
# True if there are entries that exist in the map
101
105
def empty?
102
- size == 0
106
+ @references_to_keys_map . each do |_ , ref |
107
+ return false if ref . object
108
+ end
109
+
110
+ true
103
111
end
104
112
105
113
def inspect
Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ def [](key)
33
33
value
34
34
end
35
35
36
+ alias_method :get , :[]
37
+
36
38
# Add a key/value to the map.
37
39
def []=( key , value )
38
40
ObjectSpace . define_finalizer ( value , @reference_cleanup )
@@ -49,6 +51,8 @@ def []=(key, value)
49
51
value
50
52
end
51
53
54
+ alias_method :put , :[]=
55
+
52
56
# Remove the entry associated with the key from the map.
53
57
def delete ( key )
54
58
ref = @references . delete ( key )
@@ -104,7 +108,7 @@ def merge!(other_hash)
104
108
105
109
# The number of entries in the map
106
110
def size
107
- @references . count do |key , ref |
111
+ @references . count do |_ , ref |
108
112
ref . object
109
113
end
110
114
end
@@ -113,7 +117,11 @@ def size
113
117
114
118
# True if there are entries that exist in the map
115
119
def empty?
116
- size == 0
120
+ @references . each do |_ , ref |
121
+ return false if ref . object
122
+ end
123
+
124
+ true
117
125
end
118
126
119
127
def inspect
You can’t perform that action at this time.
0 commit comments