mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user