Class: Sinclair::InputHash

Inherits:
Object show all
Defined in:
lib/sinclair/input_hash.rb

Overview

Class responsible to convert inputs into hash of default values

Author:

  • Darthjee

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.input_hash(*args) ⇒ Hash .input_hash(*args, **hash) ⇒ Hash

Converts args into Hash

Examples:

Sinclair::InputHash.input_hash(
  :key1, 'key2',
  key3: 10,
  'key4' => 20
)

# returns
# {
#   key1: nil,
#   'key2' => nil,
#   key3: 10,
#   'key4' => 20
# }

Overloads:

  • .input_hash(*args) ⇒ Hash

    Parameters:

    • args (Array)

      Names attributes

  • .input_hash(*args, **hash) ⇒ Hash

    Parameters:

    • args (Array)

      Names attributes

    • hash (Hash)

      already converted hahs

Returns:

  • (Hash)


37
38
39
# File 'lib/sinclair/input_hash.rb', line 37

def self.input_hash(*args)
  new(*args).to_h
end

Instance Method Details

#to_hHahs

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns hash from initialization arguments

Returns:

  • (Hahs)


47
48
49
# File 'lib/sinclair/input_hash.rb', line 47

def to_h
  hash_from_attributes.merge!(hash)
end