Edited string methods (#186)

* Changed numeric check regex
- `^` may match the position right after a newline character, and `$` may match right before the newline character (due to the multiline flag being enabled by default), so substing these with `\A` and `\Z`.
- Changed both instances of `[0-9]` with the shorthand `\d`.
- Removed capturing group around the first `\d+`.
* Changed get character at index
`anyString[0, 1]` is functionally the same as `anyString[0]` because the range `[a, b]` returns all characters from index `a` up to but not including the char at index `b`.
This commit is contained in:
Keyacom
2022-08-10 22:11:19 +02:00
committed by GitHub
parent a20f378b33
commit d890cd8a24

View File

@@ -23,7 +23,7 @@ end
#===============================================================================
class String
def starts_with_vowel?
return ["a", "e", "i", "o", "u"].include?(self[0, 1].downcase)
return ["a", "e", "i", "o", "u"].include?(self[0].downcase)
end
def first(n = 1); return self[0...n]; end
@@ -52,7 +52,7 @@ class String
end
def numeric?
return !self[/^[+-]?([0-9]+)(?:\.[0-9]+)?$/].nil?
return !self[/\A[+-]?\d+(?:\.\d+)?\Z/].nil?
end
end