1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Preserve multiple arguments in Symbol#start_with? and Symbol#end_with?

Followup to 62a20c2a64, for consistency
with the upstream implementation.
This commit is contained in:
Eugene Kenny 2020-05-06 03:04:42 +01:00
parent 46f90534b7
commit 343638d7d9
2 changed files with 12 additions and 4 deletions

View file

@ -1,12 +1,12 @@
# frozen_string_literal: true
class Symbol
def start_with?(prefix)
to_s.start_with?(prefix)
def start_with?(*prefixes)
to_s.start_with?(*prefixes)
end unless :a.respond_to?(:start_with?)
def end_with?(suffix)
to_s.end_with?(suffix)
def end_with?(*suffixes)
to_s.end_with?(*suffixes)
end unless :a.respond_to?(:end_with?)
alias :starts_with? :start_with?

View file

@ -9,10 +9,14 @@ class SymbolStartsEndsWithTest < ActiveSupport::TestCase
assert s.start_with?("h")
assert s.start_with?("hel")
assert_not s.start_with?("el")
assert s.start_with?("he", "lo")
assert_not s.start_with?("el", "lo")
assert s.end_with?("o")
assert s.end_with?("lo")
assert_not s.end_with?("el")
assert s.end_with?("he", "lo")
assert_not s.end_with?("he", "ll")
end
def test_starts_ends_with_alias
@ -20,9 +24,13 @@ class SymbolStartsEndsWithTest < ActiveSupport::TestCase
assert s.starts_with?("h")
assert s.starts_with?("hel")
assert_not s.starts_with?("el")
assert s.starts_with?("he", "lo")
assert_not s.starts_with?("el", "lo")
assert s.ends_with?("o")
assert s.ends_with?("lo")
assert_not s.ends_with?("el")
assert s.ends_with?("he", "lo")
assert_not s.ends_with?("he", "ll")
end
end