@@ -166,20 +166,20 @@ def initialize(value, language: nil, datatype: nil, lexical: nil, validate: fals
166166 @object = value . freeze
167167 @string = lexical if lexical
168168 @string = value if !defined? ( @string ) && value . is_a? ( String )
169- @string = @string . encode ( Encoding ::UTF_8 ) . freeze if @string
170- @object = @string if @string && @object . is_a? ( String )
169+ @string = @string . encode ( Encoding ::UTF_8 ) . freeze if instance_variable_defined? ( : @string)
170+ @object = @string if instance_variable_defined? ( : @string) && @object . is_a? ( String )
171171 @language = language . to_s . downcase . to_sym if language
172172 @datatype = RDF ::URI ( datatype ) . freeze if datatype
173173 @datatype ||= self . class . const_get ( :DATATYPE ) if self . class . const_defined? ( :DATATYPE )
174- @datatype ||= @language ? RDF . langString : RDF ::URI ( "http://www.w3.org/2001/XMLSchema#string" )
174+ @datatype ||= instance_variable_defined? ( :@language ) && @language ? RDF . langString : RDF ::URI ( "http://www.w3.org/2001/XMLSchema#string" )
175175 end
176176
177177 ##
178178 # Returns the value as a string.
179179 #
180180 # @return [String]
181181 def value
182- @string || to_s
182+ instance_variable_defined? ( :@string ) && @string || to_s
183183 end
184184
185185 ##
@@ -431,12 +431,10 @@ def comperable_datatype?(other)
431431 end
432432
433433 ##
434- # Returns `true` if the literal has a datatype and the comparison should
435- # return false instead of raise a type error.
434+ # Returns `true` if the literals are comperable.
436435 #
437436 # Used for <=> operator.
438437 #
439- # This behavior is intuited from SPARQL data-r2/expr-equal/eq-2-2
440438 # @return [Boolean]
441439 def comperable_datatype2? ( other )
442440 case self
@@ -445,13 +443,9 @@ def comperable_datatype2?(other)
445443 when RDF ::Literal ::Numeric , RDF ::Literal ::Boolean
446444 true
447445 else
448- self . plain? || other . plain? ||
449- self . language? || other . language? ||
450- self . datatype == other . datatype
446+ false
451447 end
452448 else
453- self . plain? || other . plain? ||
454- self . language? || other . language? ||
455449 self . datatype == other . datatype
456450 end
457451 end
0 commit comments