Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #start_with? to match String#start_with signature #444

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/rdf/model/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.map(&:to_s))
end
alias_method :starts_with?, :start_with?

Expand Down
1 change: 1 addition & 0 deletions spec/model_literal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading