From f31418aab2fb70a2cd4f273ae44b9a6d46922b72 Mon Sep 17 00:00:00 2001 From: Trey Pendragon Date: Fri, 5 Jul 2024 08:46:52 -0700 Subject: [PATCH] Update #start_with? to match String#start_with signature Faraday recently started expecting a string-like #start_with? signature, where you can pass multiple strings to test against and it returns true if any of them passes. We were passing an RDF Value to Faraday since the API was mostly consistent. It seems like the intent is to have the same API as String#start_with?, so this replicates it. --- lib/rdf/model/value.rb | 9 +++++---- spec/model_literal_spec.rb | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/rdf/model/value.rb b/lib/rdf/model/value.rb index 528c2ffb..d111965b 100644 --- a/lib/rdf/model/value.rb +++ b/lib/rdf/model/value.rb @@ -197,19 +197,20 @@ def validate! alias_method :validate, :validate! ## - # Returns `true` if this Value starts with the given `string`. + # Returns `true` if this Value starts with any of the given strings. # # @example # RDF::URI('http://example.org/').start_with?('http') #=> true # RDF::Node('_:foo').start_with?('_:bar') #=> false # RDF::Litera('Apple').start_with?('Orange') #=> false + # RDF::Litera('Apple').start_with?('Orange', 'Apple') #=> true # - # @param [String, #to_s] string + # @param [Array<#to_s>] *args Any number of strings to check against. # @return [Boolean] `true` or `false` # @see String#start_with? # @since 0.3.0 - def start_with?(string) - to_s.start_with?(string.to_s) + def start_with?(*args) + to_s.start_with?(*args) end alias_method :starts_with?, :start_with? diff --git a/spec/model_literal_spec.rb b/spec/model_literal_spec.rb index 98f83713..1cc024bf 100644 --- a/spec/model_literal_spec.rb +++ b/spec/model_literal_spec.rb @@ -195,6 +195,7 @@ def self.literals(*selector) it "#start_with?" do expect(RDF::Literal('foo')).to be_start_with('foo') expect(RDF::Literal('bar')).not_to be_start_with('foo') + expect(RDF::Literal('foo')).to be_start_with('foo', 'nope') end describe "#==" do