rb_lovely 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc6858428c1b20ccab46f7c4b561e3531853ad7a
4
- data.tar.gz: 2de01f2967e14c0149184a12b7191969b07a0821
3
+ metadata.gz: 81e2fd334254b0f4e4583898aec3b6dd84f81e0a
4
+ data.tar.gz: 00285bf3cd11e2b69fc919668beda886ee618b5d
5
5
  SHA512:
6
- metadata.gz: 23cdc3ee67aeab749cb6bc0dadb1864f4b860511d9ed511abcf7854c601f6858c34be1a8cb16b8e0f3e2ee4481dd6740188978fb1a9cf54744508bb8027b98b9
7
- data.tar.gz: 1e7d603e62caa5c32773bdcda4366a928e3e16ab47fb3392a8173904daabb7a7407093c307db312578962ef51c9bde2da57b6b0fe1fc043e0323c9594096028c
6
+ metadata.gz: 81555a532701e85a2e4dd0fd2388d895ee2810e07a273f5e039e45373d4476b8be3b3bbcf1d1a8afda11af4c0829ba7f24d28e71fd55efeda70810ea5e5e6add
7
+ data.tar.gz: 03117a51cacbb791b7529cd8691c087e0b8c4bb9c47cf95ac1d638731e1f374fc53d979b2992ceb559b75ba74776303c7465c81f02d69f492b8ce55ab639f93f
@@ -94,6 +94,12 @@ VALUE hashInitialize(int argc, VALUE *argv, VALUE self) {
94
94
  return self;
95
95
  }
96
96
 
97
+ VALUE hashFactory(VALUE clss, VALUE args) {
98
+ auto obj = rb_obj_alloc(clss);
99
+ rb_obj_call_init(obj, 1, &args);
100
+ return obj;
101
+ }
102
+
97
103
  VALUE hashClear(VALUE self) {
98
104
  Hash* hash = rubyCast<Hash>(self);
99
105
  hash->container.clear();
@@ -246,6 +252,7 @@ extern "C" {
246
252
  rb_include_module(rbHash, rb_const_get(rb_cObject, rb_intern("Enumerable")));
247
253
 
248
254
  rb_define_method(rbHash, "initialize", RUBY_METHOD_FUNC(hashInitialize), -1);
255
+ rb_define_singleton_method(rbHash, "[]", RUBY_METHOD_FUNC(hashFactory), -2);
249
256
  rb_define_method(rbHash, "clear", RUBY_METHOD_FUNC(hashClear), 0);
250
257
  rb_define_method(rbHash, "length", RUBY_METHOD_FUNC(hashLength), 0);
251
258
  rb_define_method(rbHash, "[]=", RUBY_METHOD_FUNC(hashUpdate), 2);
@@ -35,6 +35,12 @@ VALUE setInitialize(int argc, VALUE *argv, VALUE self) {
35
35
  return self;
36
36
  }
37
37
 
38
+ VALUE setFactory(VALUE clss, VALUE args) {
39
+ auto obj = rb_obj_alloc(clss);
40
+ rb_obj_call_init(obj, 1, &args);
41
+ return obj;
42
+ }
43
+
38
44
  VALUE setClear(VALUE self) {
39
45
  Set* set = rubyCast<Set>(self);
40
46
  set->clear();
@@ -212,6 +218,7 @@ extern "C" {
212
218
  rb_include_module(rbSet, rb_const_get(rb_cObject, rb_intern("Enumerable")));
213
219
 
214
220
  rb_define_method(rbSet, "initialize", RUBY_METHOD_FUNC(setInitialize), -1);
221
+ rb_define_singleton_method(rbSet, "[]", RUBY_METHOD_FUNC(setFactory), -2);
215
222
  rb_define_method(rbSet, "clear", RUBY_METHOD_FUNC(setClear), 0);
216
223
  rb_define_method(rbSet, "length", RUBY_METHOD_FUNC(setLength), 0);
217
224
  rb_define_method(rbSet, "add", RUBY_METHOD_FUNC(setAdd), 1);
data/yard.rb CHANGED
@@ -22,7 +22,7 @@ module RbLovely
22
22
  #
23
23
  # empty_set = RbLovely::SortedSet.new
24
24
  #
25
- # set = RbLovely::SortedSet.new [ Person.new('Nyamuk', 2), Person.new('Cold Rain', 9999) ]
25
+ # set = RbLovely::SortedSet [ Person.new('Nyamuk', 2), Person.new('Cold Rain', 9999) ]
26
26
  # set.add Person.new('Beards', 15)
27
27
  # set << Person.new('Anna', 12)
28
28
  # set.add Person.new('Moust', 18)
@@ -37,14 +37,25 @@ module RbLovely
37
37
  include Enumerable
38
38
 
39
39
  # @param content [Array] An array of values to insert into the set.
40
+ # @example
41
+ # set = RbLovely::SortedSet.new [3,1,2]
42
+ # expect(set.to_a).to eql [1,2,3]
40
43
  def initialize content = [] ; end
41
44
 
45
+ # Factory method for creating sorted set from array.
46
+ # @param content [Array] An array of values to insert into the created set.
47
+ # @return [SortedSet] New sorted set instance.
48
+ # @example
49
+ # set = RbLovely::SortedSet [3,1,2]
50
+ # expect(set.to_a).to eql [1,2,3]
51
+ def self.[](*content) ; end
52
+
42
53
  # Deletes first member equivalent to value.
43
54
  # @complexity O(log(n)).
44
55
  # @return The value that was removed or nil if no value was removed.
45
56
  # @param value Value to remove (each member is compared to value using the <=> method).
46
57
  # @example
47
- # set = RbLovely::SortedSet.new [ 1, 5, 3 ]
58
+ # set = RbLovely::SortedSet [ 1, 5, 3 ]
48
59
  # set.delete 3
49
60
  # expect(set.to_a).to eql [1, 5]
50
61
  def delete value ; end
@@ -53,7 +64,7 @@ module RbLovely
53
64
  # @complexity O(c).
54
65
  # @return The first value according to the <=> method defined on each member.
55
66
  # @example
56
- # set = RbLovely::SortedSet.new [4, 0, 2]
67
+ # set = RbLovely::SortedSet [4, 0, 2]
57
68
  # expect(set.first).to equal 0
58
69
  def first ; end
59
70
 
@@ -61,7 +72,7 @@ module RbLovely
61
72
  # @complexity O(c).
62
73
  # @return The first value according to the <=> method defined on each member or nil if the set is empty.
63
74
  # @example
64
- # set = RbLovely::SortedSet.new [4, 0, 2]
75
+ # set = RbLovely::SortedSet [4, 0, 2]
65
76
  # expect(set.shift).to equal 0
66
77
  def shift ; end
67
78
 
@@ -69,7 +80,7 @@ module RbLovely
69
80
  # @complexity O(c).
70
81
  # @return The last value according to the <=> method defined on each member.
71
82
  # @example
72
- # set = RbLovely::SortedSet.new [4, 0, 2]
83
+ # set = RbLovely::SortedSet [4, 0, 2]
73
84
  # expect(set.last).to equal 4
74
85
  def last ; end
75
86
 
@@ -77,7 +88,7 @@ module RbLovely
77
88
  # @complexity O(c).
78
89
  # @return The last value according to the <=> method defined on each member or nil if the set is empty.
79
90
  # @example
80
- # set = RbLovely::SortedSet.new [4, 0, 2]
91
+ # set = RbLovely::SortedSet [4, 0, 2]
81
92
  # expect(set.pop).to equal 4
82
93
  def pop ; end
83
94
 
@@ -85,7 +96,7 @@ module RbLovely
85
96
  # @complexity O(n)
86
97
  # @param predicate Items are removed from the set for which predicate returns true.
87
98
  # @example
88
- # set = RbLovely::SortedSet.new [0, 1, 2, 3]
99
+ # set = RbLovely::SortedSet [0, 1, 2, 3]
89
100
  # set.reject!(&:odd?)
90
101
  # expect(set.to_a).to eql([0, 2])
91
102
  def reject!(&predicate) ; end
@@ -94,7 +105,7 @@ module RbLovely
94
105
  # @complexity O(log n)
95
106
  # @param predicate The first item is removed which predicate returns true for.
96
107
  # @example
97
- # set = RbLovely::SortedSet.new [0, 1, 2, 3]
108
+ # set = RbLovely::SortedSet [0, 1, 2, 3]
98
109
  # set.reject!(&:odd?)
99
110
  # expect(set.to_a).to eql([0, 2, 3])
100
111
  def reject_first!(&predicate) ; end
@@ -103,7 +114,7 @@ module RbLovely
103
114
  # @complexity O(n)
104
115
  # @param predicate Items are removed from the set for which predicate does not return true.
105
116
  # @example
106
- # set = RbLovely::SortedSet.new [0, 1, 2, 3]
117
+ # set = RbLovely::SortedSet [0, 1, 2, 3]
107
118
  # set.select!(&:odd?)
108
119
  # expect(set.to_a).to eql([1, 3])
109
120
  def select!(&predicate) ; end
@@ -111,7 +122,7 @@ module RbLovely
111
122
  # Calls block once with each value in the set.
112
123
  # @complexity O(n)
113
124
  # @example
114
- # set = RbLovely::SortedSet.new [0, 1, 2, 3]
125
+ # set = RbLovely::SortedSet [0, 1, 2, 3]
115
126
  # set.each { |x| puts x }
116
127
  def each(&block) ; end
117
128
  end
@@ -129,7 +140,7 @@ module RbLovely
129
140
  # empty_hash = RbLovely::SortedHash.new
130
141
  #
131
142
  # # constructor is like: hash[20] = 5 ; hash[9] = 1
132
- # hash = RbLovely::SortedHash.new [20, 5, 9, 1]
143
+ # hash = RbLovely::SortedHash [20, 5, 9, 1]
133
144
  # hash[2] = 16
134
145
  # hash[20] = 4 # updates previous value
135
146
  # expect(hash[20]).to equal 4
@@ -141,7 +152,7 @@ module RbLovely
141
152
  # @param compare [Proc] Comparison function used to order values (rather than default
142
153
  # of using <=> method).
143
154
  # @example
144
- # hash = RbLovely::SortedHash.new([:a, 10, :c, 5, :b, 1 ])
155
+ # hash = RbLovely::SortedHash.new [:a, 10, :c, 5, :b, 1 ]
145
156
  # expect(hash.to_a).to eql [[:b, 1], [:c, 5], [:a, 10]]
146
157
  #
147
158
  # # compare function reverses default sort order
@@ -152,10 +163,18 @@ module RbLovely
152
163
  # expect(hash.to_a).to eql [[:b, 10], [:c, 5], [:a, 1 ]]
153
164
  def initialize content = [], compare: nil ; end
154
165
 
166
+ # Factory method for creating sorted hash from array.
167
+ # @param content [Array] An array of values to insert into the created hash.
168
+ # @return [SortedHash] New sorted set instance.
169
+ # @example
170
+ # hash = RbLovely::SortedHash [:a, 3, :b, 1]
171
+ # expect(hash.to_a).to eql [[:b, 1], [:a, 3]]
172
+ def self.[](*content) ; end
173
+
155
174
  # Delete the value associated with a key.
156
175
  # @return The value associated with the deleted key or nil if the key was not in the hash.
157
176
  # @example
158
- # hash = RbLovely::SortedHash.new([:a, 5 ])
177
+ # hash = RbLovely::SortedHash [:a, 5 ]
159
178
  # expect(hash.delete(:a)).to equal 5
160
179
  # expect(hash.delete(:b)).to equal nil
161
180
  def delete key ; end
@@ -163,14 +182,14 @@ module RbLovely
163
182
  # Calls block once for each key, passing the key-value pair as parameters.
164
183
  # @complexity O(n)
165
184
  # @example
166
- # hash = RbLovely::SortedHash.new [:a, 10, :b, 1]
185
+ # hash = RbLovely::SortedHash [:a, 10, :b, 1]
167
186
  # # This would call the block in value order: with (:b, 1) followed by (:a, 10).
168
187
  # hash.each { |key, value| puts "#{key} => #{value}" }
169
188
  def each(&block) ; end
170
189
 
171
190
  # Remove all values from the hash.
172
191
  # @example
173
- # hash = RbLovely::SortedHash.new [:a, 10]
192
+ # hash = RbLovely::SortedHash [:a, 10]
174
193
  # hash.clear
175
194
  # expect(hash.length).to equal 0
176
195
  def clear ; end
@@ -178,7 +197,7 @@ module RbLovely
178
197
  # Retrieve value associated with the corresponding key or nil if the key doesn't exist.
179
198
  # @complexity O(c)
180
199
  # @example
181
- # hash = RbLovely::SortedHash.new [:a, 2]
200
+ # hash = RbLovely::SortedHash [:a, 2]
182
201
  # expect(hash[:a]).to equal 2
183
202
  # expect(hash[:b]).to equal nil
184
203
  def [](key) ; end
@@ -186,10 +205,10 @@ module RbLovely
186
205
  # Return true if the key is contained in the hash.
187
206
  def include?(key) ; end
188
207
 
189
- # Retrieve first value sorted by <=> or comparison function or nil if the hash is empty.
208
+ # Retrieve first value as determined by value sort order or nil if the hash is empty.
190
209
  def first ; end
191
210
 
192
- # Retrieve last value sorted by <=> or comparison function or nil if the hash is empty.
211
+ # Retrieve last value as determined by value sort order or nil if the hash is empty.
193
212
  def last ; end
194
213
 
195
214
  alias :has_key? :include?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_lovely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pike