Skip to content

Commit cae8390

Browse files
doriantaylorgkellogg
authored andcommitted
short-circuiting slow inherited methods with fast ones
1 parent f52e8cc commit cae8390

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

lib/rdf/model/graph.rb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module RDF
2020
#
2121
# @example Loading graph data from a URL
2222
# require 'rdf/rdfxml' # for RDF/XML support
23-
#
23+
#
2424
# graph = RDF::Graph.load("http://www.bbc.co.uk/programmes/b0081dq5.rdf")
2525
#
2626
# @example Accessing a specific named graph within a {RDF::Repository}
@@ -250,6 +250,36 @@ def statement?(*args)
250250
end
251251
alias_method :has_statement?, :statement?
252252

253+
##
254+
# Returns `true` if `self` contains the given RDF subject term.
255+
#
256+
# @param [RDF::Resource] value
257+
# @return [Boolean]
258+
def subject? value
259+
!@data.query({ subject: value, graph_name: graph_name || false }).empty?
260+
end
261+
alias_method :has_subject?, :subject?
262+
263+
##
264+
# Returns `true` if `self` contains the given RDF predicate term.
265+
#
266+
# @param [RDF::URI] value
267+
# @return [Boolean]
268+
def predicate? value
269+
!@data.query({ predicate: value, graph_name: graph_name || false }).empty?
270+
end
271+
alias_method :has_predicate?, :predicate?
272+
273+
##
274+
# Returns `true` if `self` contains the given RDF object term.
275+
#
276+
# @param [RDF::Term] value
277+
# @return [Boolean]
278+
def object? value
279+
!@data.query({ object: value, graph_name: graph_name || false }).empty?
280+
end
281+
alias_method :has_object?, :object?
282+
253283
##
254284
# Enumerates each RDF statement in this graph.
255285
#

0 commit comments

Comments
 (0)