Class: Object

Inherits:
BasicObject
Defined in:
lib/musa-dsl/core-ext/arrayfy.rb,
lib/musa-dsl/core-ext/hashify.rb,
lib/musa-dsl/core-ext/deep-copy.rb,
lib/musa-dsl/core-ext/deep-copy.rb

Instance Method Summary collapse

Instance Method Details

#arrayfy(size: nil, default: nil) ⇒ Array

Note:

This method is added to Object via refinement. Requires using Musa::Extension::Arrayfy.

Converts any object into an array, optionally repeated to a target size.

Examples:

With size

using Musa::Extension::Arrayfy
"hello".arrayfy(size: 3)  # => ["hello", "hello", "hello"]

Nil handling

using Musa::Extension::Arrayfy
nil.arrayfy(size: 2, default: :empty)  # => [:empty, :empty]

Parameters:

  • size (Integer, nil) (defaults to: nil)

    target array length. If nil, returns single-element array.

  • default (Object, nil) (defaults to: nil)

    value to use instead of nil.

Returns:

  • (Array)

    single element repeated size times, or wrapped in array if size is nil.



83
# File 'lib/musa-dsl/core-ext/arrayfy.rb', line 83

class ::Object; end

#clone(freeze: nil, deep: false) ⇒ Object

Note:

This method is added to Object via refinement. Requires using Musa::Extension::DeepCopy.

Enhanced clone with optional deep copy.

Examples:

Deep clone with freeze control

using Musa::Extension::DeepCopy
hash = { nested: { value: 1 } }
copy = hash.clone(deep: true, freeze: true)
copy.frozen?  # => true
copy[:nested].frozen?  # => true (deep freeze)

Parameters:

  • freeze (Boolean, nil) (defaults to: nil)

    whether to freeze the clone.

  • deep (Boolean) (defaults to: false)

    if true, performs deep copy; if false, standard clone.

Returns:

  • (Object)

    cloned object (shallow or deep).



297
# File 'lib/musa-dsl/core-ext/deep-copy.rb', line 297

class ::Object; end

#dup(deep: false) ⇒ Object

Note:

This method is added to Object via refinement. Requires using Musa::Extension::DeepCopy.

Enhanced dup with optional deep copy.

Examples:

Shallow dup (default)

using Musa::Extension::DeepCopy
arr = [[1, 2]]
copy = arr.dup
copy[0] << 3
arr  # => [[1, 2, 3]] (inner array shared)

Deep dup

using Musa::Extension::DeepCopy
arr = [[1, 2]]
copy = arr.dup(deep: true)
copy[0] << 3
arr  # => [[1, 2]] (inner array independent)

Parameters:

  • deep (Boolean) (defaults to: false)

    if true, performs deep copy; if false, standard dup.

Returns:

  • (Object)

    duplicated object (shallow or deep).



279
# File 'lib/musa-dsl/core-ext/deep-copy.rb', line 279

class ::Object; end

#hashify(keys:, default: nil) ⇒ Hash

Note:

This method is added to Object via refinement. Requires using Musa::Extension::Hashify.

Creates a hash mapping all specified keys to this object's value.

Useful for broadcasting a single value across multiple attributes. Nil objects can be replaced with a default value.

Examples:

Single value to multiple keys

using Musa::Extension::Hashify
127.hashify(keys: [:velocity, :pressure])
# => { velocity: 127, pressure: 127 }

Parameters:

  • keys (Array<Symbol>)

    keys for the resulting hash.

  • default (Object, nil) (defaults to: nil)

    value to use if self is nil.

Returns:

  • (Hash)

    hash with all keys mapped to self (or default if nil).



94
# File 'lib/musa-dsl/core-ext/hashify.rb', line 94

class ::Object; end