Class: String
- Defined in:
- runtime/ext/string.rb,
runtime/ext/date.rbs,
runtime/ext/string.rbs,
runtime/ext/date.rb
Overview
String — the text helpers.
Instance Method Summary collapse
-
#camelize(mode = :upper) ⇒ String
"host_info"→"HostInfo", or"hostInfo"withmode: :lower: underscore-separated words capitalized, a/read as a namespace separator ("a/b"→"A::B"). -
#humanize ⇒ String
"foo_bar"→"Foo bar": underscores to spaces, a trailing " id" dropped, first letter upcased. -
#parameterize ⇒ String
this text as a URL slug: downcased, with every run of characters outside
a-z,0-9and "_" folded into a single "-", runs of "-" collapsed, and "-" trimmed off both ends. -
#pluralize(count) ⇒ String
the plural of this word, or the word unchanged when
count == 1: the word a count labels, singular for one item and plural for every other count. -
#squish ⇒ String
whitespace runs collapse to one space and the ends strip: the shape
<<~SQL.squishproduces. -
#titleize ⇒ String
"foo_bar"→"Foo Bar": each word's first letter upcased. -
#to_date ⇒ Date?
"2024-01-02"→ the civil date a stored DATE column holds. -
#to_time ⇒ Time?
"2024-01-02 03:04:05.000006"→ the instant, in the app's configured zone: a stored datetime column read back. -
#underscore ⇒ String
"FooBar"→"foo_bar": camel boundaries split,-reads as_, the result downcased.
Instance Method Details
#camelize(mode = :upper) ⇒ String
"host_info" → "HostInfo", or "hostInfo" with mode: :lower:
underscore-separated words capitalized, a / read as a namespace separator
("a/b" → "A::B"). The shape JSON keys need when a payload is camelCase.
64 |
# File 'runtime/ext/string.rb', line 64
def camelize: (?Symbol mode) -> String
|
#humanize ⇒ String
"foo_bar" → "Foo bar": underscores to spaces, a trailing " id" dropped,
first letter upcased.
101 |
# File 'runtime/ext/string.rb', line 101
def humanize: () -> String
|
#parameterize ⇒ String
this text as a URL slug: downcased, with every run of characters outside
a-z, 0-9 and "_" folded into a single "-", runs of "-" collapsed, and
"-" trimmed off both ends.
Letters outside ASCII are dropped rather than transliterated, so a non-Latin word parameterizes to an empty string.
175 |
# File 'runtime/ext/string.rb', line 175
def parameterize: () -> String
|
#pluralize(count) ⇒ String
the plural of this word, or the word unchanged when count == 1: the word a
count labels, singular for one item and plural for every other count.
The suffix rules are the regular English ones, not the full irregular tables: a consonant before "y" turns to "ies" ("category"), "x", "z", "ch" and "sh" take "es" ("box", "church"), and a word that already ends in "s" keeps its form ("posts").
141 |
# File 'runtime/ext/string.rb', line 141
def pluralize: (Integer count) -> String
|
#squish ⇒ String
whitespace runs collapse to one space and the ends strip: the shape
<<~SQL.squish produces. The scan is spelled out because a regex is not a
form the compiler lowers.
9 |
# File 'runtime/ext/string.rb', line 9
def squish: () -> String
|
#titleize ⇒ String
"foo_bar" → "Foo Bar": each word's first letter upcased.
112 |
# File 'runtime/ext/string.rb', line 112
def titleize: () -> String
|
#to_date ⇒ Date?
"2024-01-02" → the civil date a stored DATE column holds. The parse is the
stored form's fixed width, not a general date parser: the first ten
characters are the date and shorter text reads nil, so a datetime text and a
date text do not answer through one parser. A well-width text that is not a
real calendar date raises through Date.new instead of turning into nil.
24 |
# File 'runtime/ext/date.rb', line 24
def to_date: () -> Date?
|
#to_time ⇒ Time?
"2024-01-02 03:04:05.000006" → the instant, in the app's configured zone:
a stored datetime column read back. Text too short to carry an instant reads
nil. The parse is the stored form's fixed width, not a date-parser pipeline:
the storage form is the contract, and the micros stay in Time.utc's
seventh argument (a float added afterwards loses a microsecond and skews
> ? bounds). The zone comes from the process TZ, which
config/environment.rb pins, so the answer arrives in the app zone without
a lookup.
207 |
# File 'runtime/ext/string.rb', line 207
def to_time: () -> Time?
|
#underscore ⇒ String
"FooBar" → "foo_bar": camel boundaries split, - reads as _, the
result downcased. The walk is spelled out rather than a regex pipeline, and
no acronym or human-name table is modeled.
32 |
# File 'runtime/ext/string.rb', line 32
def underscore: () -> String
|