Module: CMDx::Coercions::String

Extended by:
String
Included in:
String
Defined in:
lib/cmdx/coercions/string.rb

Overview

Coerces values to String type using Ruby’s built-in String() method.

This coercion handles various input types by converting them to their string representation. It’s a simple wrapper around Ruby’s String() method for consistency with the CMDx coercion interface.

Instance Method Summary collapse

Instance Method Details

#call(value, options = {}) ⇒ String

Coerces a value to String type.

Examples:

Basic string coercion

String.call("hello")           # => "hello"
String.call(42)                # => "42"
String.call([1, 2, 3])         # => "[1, 2, 3]"
String.call(nil)               # => ""
String.call(true)              # => "true"

Parameters:

  • value (Object)

    The value to coerce to a string

  • options (Hash) (defaults to: {})

    Optional configuration parameters (unused in this coercion)

Options Hash (options):

  • :* (Object)

    Any configuration option (unused)

Returns:

  • (String)

    The coerced string value

Raises:

  • (TypeError)

    If the value cannot be converted to a string



32
33
34
# File 'lib/cmdx/coercions/string.rb', line 32

def call(value, options = {})
  String(value)
end