Skip to content

Commit ca8db65

Browse files
tpendragongkellogg
authored andcommitted
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.
1 parent 5e32ea6 commit ca8db65

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

lib/rdf/model/value.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,20 @@ def validate!
197197
alias_method :validate, :validate!
198198

199199
##
200-
# Returns `true` if this Value starts with the given `string`.
200+
# Returns `true` if this Value starts with any of the given strings.
201201
#
202202
# @example
203203
# RDF::URI('http://example.org/').start_with?('http') #=> true
204204
# RDF::Node('_:foo').start_with?('_:bar') #=> false
205205
# RDF::Litera('Apple').start_with?('Orange') #=> false
206+
# RDF::Litera('Apple').start_with?('Orange', 'Apple') #=> true
206207
#
207-
# @param [String, #to_s] string
208+
# @param [Array<#to_s>] *args Any number of strings to check against.
208209
# @return [Boolean] `true` or `false`
209210
# @see String#start_with?
210211
# @since 0.3.0
211-
def start_with?(string)
212-
to_s.start_with?(string.to_s)
212+
def start_with?(*args)
213+
to_s.start_with?(*args.map(&:to_s))
213214
end
214215
alias_method :starts_with?, :start_with?
215216

spec/model_literal_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def self.literals(*selector)
195195
it "#start_with?" do
196196
expect(RDF::Literal('foo')).to be_start_with('foo')
197197
expect(RDF::Literal('bar')).not_to be_start_with('foo')
198+
expect(RDF::Literal('foo')).to be_start_with('foo', 'nope')
198199
end
199200

200201
describe "#==" do

0 commit comments

Comments
 (0)