Documentation
¶
Overview ¶
Package coreext is a pure-Go (no cgo), MRI-faithful reimplementation of the highest-value ActiveSupport core-extension helpers (String, Array, Hash, Object/Numeric, Enumerable). Each helper is a plain Go function that the rbgo binding maps onto the corresponding Ruby monkey-patch.
Representation choices (documented so the rbgo binding can map cleanly):
- Ruby String → Go string (helpers are rune-aware where Ruby is character-aware).
- Ruby Array → Go []any (nil padding is represented by Go nil).
- Ruby Hash → Go map[any]any so string and Symbol keys can coexist.
- Ruby Symbol → the Symbol type below.
- Behaviour that needs Ruby object semantics (Object#try, blank? on an arbitrary object) is reached through an explicit seam (Dispatcher / Blankable) the binding supplies.
String inflection helpers (Pluralize, Camelize, …) delegate to the sibling inflector package, so they inherit its byte-for-byte MRI fidelity.
Index ¶
- func ArrayBlank(a []any) bool
- func ArrayFrom(a []any, pos int) ([]any, bool)
- func ArrayTo(a []any, pos int) []any
- func AssertValidKeys(h map[any]any, valid ...any) error
- func At(s string, pos int) (string, bool)
- func Blank(v any) bool
- func Camelize(s string) string
- func CamelizeLower(s string) string
- func Classify(s string) string
- func Dasherize(s string) string
- func DeepDup(h map[any]any) map[any]any
- func DeepMerge(h, other map[any]any) map[any]any
- func DeepMergeInto(h, other map[any]any) map[any]any
- func DeepStringifyKeys(h map[any]any) map[any]any
- func DeepSymbolizeKeys(h map[any]any) map[any]any
- func DeepTransformValues(h map[any]any, fn func(any) any) map[any]any
- func EndsWith(s, suffix string) bool
- func Except(h map[any]any, keys ...any) map[any]any
- func Exclude(items []any, v any) bool
- func ExtractOptions(a []any) ([]any, map[any]any)
- func Fifth(a []any) any
- func First(s string, n int) string
- func FirstChar(s string) string
- func Fourth(a []any) any
- func From(s string, pos int) (string, bool)
- func HashBlank(h map[any]any) bool
- func Humanize(s string) string
- func InGroups(a []any, number int, fill any) [][]any
- func InGroupsNoFill(a []any, number int) [][]any
- func InGroupsOf(a []any, number int, fill any) [][]any
- func InGroupsOfNoFill(a []any, number int) [][]any
- func Indent(s string, amount int, indentChar string, indentEmptyLines bool) string
- func IndexBy(items []any, key func(any) any) map[any]any
- func Last(s string, n int) string
- func LastChar(s string) string
- func Many(items []any) bool
- func ManyBy(items []any, pred func(any) bool) bool
- func MultipleOf(n, m int) bool
- func Ordinal(n int) string
- func Ordinalize(n int) string
- func Parameterize(s string) string
- func Pick(items []any, key func(any) any) (any, bool)
- func Pluck(items []any, key func(any) any) []any
- func Pluralize(s string) string
- func Presence(v any) any
- func Present(v any) bool
- func Remove(s string, patterns ...string) string
- func ReverseMerge(h, other map[any]any) map[any]any
- func Second(a []any) any
- func Singularize(s string) string
- func Slice(h map[any]any, keys ...any) map[any]any
- func Split(a []any, sep any) [][]any
- func Squish(s string) string
- func StartsWith(s, prefix string) bool
- func StringBlank(s string) bool
- func StringPresence(s string) (string, bool)
- func StringPresent(s string) bool
- func StringifyKeys(h map[any]any) map[any]any
- func StripHeredoc(s string) string
- func Sum(items []any, init float64, project func(any) float64) float64
- func SymbolizeKeys(h map[any]any) map[any]any
- func Tableize(s string) string
- func Third(a []any) any
- func Titleize(s string) string
- func To(s string, pos int) string
- func ToSentence(items []any) string
- func ToSentenceWith(items []any, wordsConnector, twoWordsConnector, lastWordConnector string) string
- func Truncate(s string, length int, omission, separator string) string
- func TruncateWords(s string, wordsCount int, omission string) string
- func Try(recv any, dispatch Dispatcher, method string, args ...any) any
- func Underscore(s string) string
- type Blankable
- type Dispatcher
- type Symbol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArrayBlank ¶
ArrayBlank reports whether the array is empty (Array#blank?).
func ArrayFrom ¶
ArrayFrom returns the elements from index pos to the end (negative counts from the end), reporting false when pos is past the end (Array#from).
func ArrayTo ¶
ArrayTo returns the elements from the start through index pos inclusive (negative counts from the end) (Array#to).
func AssertValidKeys ¶
AssertValidKeys returns an error if h contains a key not in valid, mirroring Hash#assert_valid_keys (which raises ArgumentError).
func At ¶
At returns the character at position pos (negative counts from the end), reporting false when pos is out of range (String#at / String#[]).
func Blank ¶
Blank reports whether v is "blank" in the ActiveSupport sense: nil, false, an empty/whitespace string, an empty array or hash, or a Blankable that says so. Everything else (including any number) is present (Object#blank?).
func CamelizeLower ¶
CamelizeLower converts s to lowerCamelCase (String#camelize(:lower)).
func DeepDup ¶
DeepDup returns a recursive copy of h, duplicating nested hashes and slices (Hash#deep_dup).
func DeepMerge ¶
DeepMerge returns a new hash merging other into h recursively: when both values for a key are hashes they are deep-merged, otherwise other wins (Hash#deep_merge).
func DeepMergeInto ¶
DeepMergeInto merges other into h in place and returns h (Hash#deep_merge!).
func DeepStringifyKeys ¶
DeepStringifyKeys is StringifyKeys applied recursively to nested hashes (Hash#deep_stringify_keys).
func DeepSymbolizeKeys ¶
DeepSymbolizeKeys is SymbolizeKeys applied recursively to nested hashes (Hash#deep_symbolize_keys).
func DeepTransformValues ¶
DeepTransformValues returns a copy of h with fn applied to every value, recursing into nested hashes and slices (Hash#deep_transform_values).
func ExtractOptions ¶
ExtractOptions removes and returns a trailing options hash, mirroring Array#extract_options!. It returns the remaining elements and the options (an empty map when the last element is not a map[any]any).
func First ¶
First returns the first n characters of s (String#first). n defaults to 1 via FirstChar; values past the length return the whole string, 0 returns "".
func From ¶
From returns the substring from position pos to the end (negative counts from the end), reporting false when pos is past the end (String#from).
func InGroups ¶
InGroups splits a into number groups, padding shorter groups with fill (Array#in_groups). Use InGroupsNoFill to leave short groups unpadded.
func InGroupsNoFill ¶
InGroupsNoFill splits a into number groups without padding (Array#in_groups(n, false)).
func InGroupsOf ¶
InGroupsOf splits a into consecutive groups of number elements, padding the final group with fill (Array#in_groups_of).
func InGroupsOfNoFill ¶
InGroupsOfNoFill splits a into groups of number elements without padding the final group (Array#in_groups_of(n, false)).
func Indent ¶
Indent prefixes each non-skipped line of s with amount copies of indentChar (default " "). Empty lines are indented only when indentEmptyLines is true (String#indent).
func IndexBy ¶
IndexBy builds a map from key(elem) to the last element with that key (Enumerable#index_by).
func ManyBy ¶
ManyBy reports whether more than one element satisfies pred (Enumerable#many? with a block).
func MultipleOf ¶
MultipleOf reports whether n is an integer multiple of m (Integer#multiple_of?). When m is zero, only zero is a multiple.
func Ordinalize ¶
Ordinalize renders n with its ordinal suffix (Integer#ordinalize).
func Parameterize ¶
Parameterize slugifies s with a "-" separator (String#parameterize).
func Pick ¶
Pick returns key(elem) for the first element, reporting false when items is empty (Enumerable#pick).
func ReverseMerge ¶
ReverseMerge returns other merged with h, where h's values win on conflict (Hash#reverse_merge).
func Singularize ¶
Singularize returns the singular of s (String#singularize).
func Slice ¶
Slice returns a copy of h containing only the given keys that are present (Hash#slice).
func Split ¶
Split divides a into subarrays separated by every element equal to sep (Array#split with a value).
func Squish ¶
Squish strips leading/trailing whitespace and collapses internal whitespace runs to a single space (String#squish).
func StartsWith ¶
StartsWith reports whether s begins with prefix (String#starts_with?).
func StringBlank ¶
StringBlank reports whether s is empty or contains only whitespace (ActiveSupport's String#blank?, matching /\A[[:space:]]*\z/).
func StringPresence ¶
StringPresence returns (s, true) when s is present, or ("", false) when it is blank (String#presence returns the string or nil).
func StringPresent ¶
StringPresent is the inverse of StringBlank (String#present?).
func StringifyKeys ¶
StringifyKeys returns a copy of h with every key converted to its string form (Hash#stringify_keys).
func StripHeredoc ¶
StripHeredoc removes the smallest common leading indentation from every line (String#strip_heredoc).
func Sum ¶
Sum adds init to the sum of project(elem) over items (Enumerable#sum). Pass a nil project to sum the elements themselves when they are float64.
func SymbolizeKeys ¶
SymbolizeKeys returns a copy of h with string keys converted to Symbol (Hash#symbolize_keys). Non-string keys are left unchanged.
func To ¶
To returns the substring from the start through position pos inclusive (negative counts from the end) (String#to).
func ToSentence ¶
ToSentence joins items into a human sentence using the default English connectors ("a, b, and c") (Array#to_sentence).
func ToSentenceWith ¶
func ToSentenceWith(items []any, wordsConnector, twoWordsConnector, lastWordConnector string) string
ToSentenceWith joins items using explicit connectors (Array#to_sentence with :words_connector / :two_words_connector / :last_word_connector).
func Truncate ¶
Truncate shortens s to at most length characters, appending omission (default "..." when empty). When separator is non-empty, the cut is moved back to the last separator boundary (String#truncate).
func TruncateWords ¶
TruncateWords keeps the first wordsCount whitespace-separated words, appending omission (default "...") when the text is longer (String#truncate_words).
func Try ¶
func Try(recv any, dispatch Dispatcher, method string, args ...any) any
Try invokes method on recv through dispatch, returning nil when recv is nil or does not respond to method (Object#try). This is the safe-navigation helper; dispatch is the Ruby-semantics seam.
func Underscore ¶
Underscore converts s to snake_case (String#underscore).
Types ¶
type Blankable ¶
type Blankable interface{ IsBlank() bool }
Blankable is the seam for objects that define their own blank? via an empty?-like predicate. The rbgo binding implements it for Ruby objects that respond to empty?.
type Dispatcher ¶
Dispatcher is the method-dispatch seam used by Try: it invokes method on recv and reports whether recv responds to it. The rbgo binding backs this with the Ruby object model.