Method: RDF::Query::Pattern#variable_count

Defined in:
lib/rdf/query/pattern.rb

#variable_countInteger Also known as: cardinality, arity

Returns the number of variables in this pattern.

Note: this does not count distinct variables, and will therefore e.g. return 3 even if two terms are actually the same variable.

Returns:

  • (Integer)

    (0..3)

Since:

  • 0.3.0



272
273
274
275
276
277
# File 'lib/rdf/query/pattern.rb', line 272

def variable_count
  [subject, predicate, object, graph_name].inject(0) do |memo, term|
    memo += (term.is_a?(Variable) ? 1 :
             (term.respond_to?(:variable_count) ? term.variable_count : 0))
  end
end