Skip to content

Commit 2075320

Browse files
committed
Update RDF::List to use self.class, rather than RDF::List to allow it to be more easily subclassed.
1 parent fc8cf7e commit 2075320

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

lib/rdf/model/list.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def self.[](*values)
4545
# identified by `subject`, but will be invalid.
4646
#
4747
# @example add constructed list to existing graph
48-
# l = RDF::List(nil, nil (1, 2, 3))
48+
# l = RDF::List(values: (1, 2, 3))
4949
# g = RDF::Graph.new << l
5050
# g.count # => l.count
5151
#
@@ -175,7 +175,7 @@ def ==(other)
175175
# @return [RDF::List]
176176
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-26
177177
def &(other)
178-
RDF::List[*(to_a & other.to_a)]
178+
self.class.new(values: (to_a & other.to_a))
179179
end
180180

181181
##
@@ -193,7 +193,7 @@ def &(other)
193193
# @return [RDF::List]
194194
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-7C
195195
def |(other)
196-
RDF::List[*(to_a | other.to_a)]
196+
self.class.new(values: (to_a | other.to_a))
197197
end
198198

199199
##
@@ -206,7 +206,7 @@ def |(other)
206206
# @return [RDF::List]
207207
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-2B
208208
def +(other)
209-
RDF::List[*(to_a + other.to_a)]
209+
self.class.new(values: (to_a + other.to_a))
210210
end
211211

212212
##
@@ -220,7 +220,7 @@ def +(other)
220220
# @return [RDF::List]
221221
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-2D
222222
def -(other)
223-
RDF::List[*(to_a - other.to_a)]
223+
self.class.new(values: (to_a - other.to_a))
224224
end
225225

226226
##
@@ -250,7 +250,7 @@ def -(other)
250250
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-2A
251251
def *(int_or_str)
252252
case int_or_str
253-
when Integer then RDF::List[*(to_a * int_or_str)]
253+
when Integer then self.class.new(values: (to_a * int_or_str))
254254
else join(int_or_str.to_s)
255255
end
256256
end
@@ -538,13 +538,13 @@ def slice(*args)
538538
##
539539
# @private
540540
def slice_with_start_and_length(start, length)
541-
RDF::List[*to_a.slice(start, length)]
541+
self.class.new(values: to_a.slice(start, length))
542542
end
543543

544544
##
545545
# @private
546546
def slice_with_range(range)
547-
RDF::List[*to_a.slice(range)]
547+
self.class.new(values: to_a.slice(range))
548548
end
549549

550550
protected :slice_with_start_and_length
@@ -851,7 +851,7 @@ def join(sep = $,)
851851
# @return [RDF::List]
852852
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-reverse
853853
def reverse
854-
RDF::List[*to_a.reverse]
854+
self.class.new(values: to_a.reverse)
855855
end
856856

857857
##
@@ -863,7 +863,7 @@ def reverse
863863
# @return [RDF::List]
864864
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-sort
865865
def sort(&block)
866-
RDF::List[*super]
866+
self.class.new(values: super)
867867
end
868868

869869
##
@@ -875,7 +875,7 @@ def sort(&block)
875875
# @return [RDF::List]
876876
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-sort_by
877877
def sort_by(&block)
878-
RDF::List[*super]
878+
self.class.new(values: super)
879879
end
880880

881881
##
@@ -887,7 +887,7 @@ def sort_by(&block)
887887
# @return [RDF::List]
888888
# @see http://ruby-doc.org/core-2.2.2/Array.html#method-i-uniq
889889
def uniq
890-
RDF::List[*to_a.uniq]
890+
self.class.new(values: to_a.uniq)
891891
end
892892

893893
##
@@ -964,7 +964,7 @@ def normalize_value(value)
964964
case value
965965
when nil then RDF.nil
966966
when RDF::Value then value
967-
when Array then RDF::List.new(subject: nil, graph: graph, values: value)
967+
when Array then self.class.new(subject: nil, graph: graph, values: value)
968968
else value
969969
end
970970
end

0 commit comments

Comments
 (0)