lib/rdf/model/statement.rb in rdf-1.1.16.1 vs lib/rdf/model/statement.rb in rdf-1.1.17

- old
+ new

@@ -77,42 +77,47 @@ # if not a {Resource}, it is coerced to {Literal} or {Node} depending on if it is a symbol or something other than a {Term}. # @param [Hash{Symbol => Object}] options # @option options [RDF::Term] :context (nil) # @return [RDF::Statement] def initialize(subject = nil, predicate = nil, object = nil, options = {}) - case subject - when Hash - @options = subject.dup - @subject = @options.delete(:subject) - @predicate = @options.delete(:predicate) - @object = @options.delete(:object) - else - @options = !options.empty? ? options.dup : {} - @subject = subject - @predicate = predicate - @object = object + if subject.is_a?(Hash) + @options = Hash[subject] # faster subject.dup + @subject = @options.delete(:subject) + @predicate = @options.delete(:predicate) + @object = @options.delete(:object) + else + @options = !options.empty? ? Hash[options] : {} + @subject = subject + @predicate = predicate + @object = object end @id = @options.delete(:id) if @options.has_key?(:id) @context = @options.delete(:context) initialize! end ## # @private def initialize! @context = Node.intern(@context) if @context.is_a?(Symbol) - @subject = case @subject - when nil then nil - when Symbol then Node.intern(@subject) - when Value then @subject.to_term - else raise ArgumentError, "expected subject to be nil or a term, was #{@subject.inspect}" + @subject = if @subject.is_a?(Value) + @subject.to_term + elsif @subject.is_a?(Symbol) + Node.intern(@subject) + elsif @subject.nil? + nil + else + raise ArgumentError, "expected subject to be nil or a term, was #{@subject.inspect}" end @predicate = Node.intern(@predicate) if @predicate.is_a?(Symbol) - @object = case @object - when nil then nil - when Symbol then Node.intern(@object) - when Value then @object.to_term - else Literal.new(@object) + @object = if @object.is_a?(Value) + @object.to_term + elsif @object.is_a?(Symbol) + Node.intern(@object) + elsif @object.nil? + nil + else + Literal.new(@object) end end ## # Returns `true` to indicate that this value is a statement.