Class: Array

Inherits:
Object show all
Defined in:
runtime/ext/array.rb,
runtime/ext/array.rbs

Overview

Array — the collection helpers.

Instance Method Summary collapse

Instance Method Details

#deep_transform_keys(&block) ⇒ Array

a new Array whose Hash elements have the block applied to every key at every depth; non-Hash elements pass through unchanged. The receiver is untouched.

Examples:

[{ "os_name" => "ios" }].deep_transform_keys { |key| key.to_s.camelize(:lower) }
# => [{ "osName" => "ios" }]

Returns:

  • (Array) —

    a new Array with the Hash elements' keys transformed



10
# File 'runtime/ext/array.rb', line 10

def deep_transform_keys: () { (untyped key) -> untyped } -> Array[untyped]

#deep_transform_keys!(&block) ⇒ Array

the same transform in place. Unlike a typed Hash's keys, an Array's elements don't change type when only the Hash elements' keys reshape, so the bang form mutates the receiver.

Examples:

list = [{ "os_name" => "ios" }]
list.deep_transform_keys! { |key| key.to_s.camelize(:lower) }
list   # => [{ "osName" => "ios" }]

Returns:

  • (Array) —

    this Array with the Hash elements' keys transformed



23
# File 'runtime/ext/array.rb', line 23

def deep_transform_keys!: () { (untyped key) -> untyped } -> Array[untyped]

#to_sentence(words_connector: ", ", two_words_connector: " and ", last_word_connector: ", and ") ⇒ String

the elements through to_s joined in reading order: "", "a", "a and b", "a, b, and c"; each connector defaults to English prose and is overridable by keyword.

Returns:

  • (String) —

    the joined sentence



32
# File 'runtime/ext/array.rb', line 32

def to_sentence: (?words_connector: String, ?two_words_connector: String, ?last_word_connector: String) -> String