Module: AttrPlus

Defined in:
lib/attr_plus/ext.rb,
lib/attr_plus/version.rb

Overview

Place extra methods in here to avoid polluting Class and Module.

Constant Summary collapse

VERSION =
'0.4.1'

Class Method Summary collapse

Class Method Details

.separate_arguments(args) ⇒ Array[Array, Object]

Returns An array where the first item is a list of arguments that were passed and the second (last) item is a default value that was given or nil.

Parameters:

  • args (Array)

Returns:

  • (Array[Array, Object])

    An array where the first item is a list of arguments that were passed and the second (last) item is a default value that was given or nil.



10
11
12
13
14
15
16
17
18
# File 'lib/attr_plus/ext.rb', line 10

def self.separate_arguments(args)
  if args.size == 1 && args.first.is_a?(Hash)
    [[args.first.keys[0]], args.first.values[0]]
  elsif args.last.is_a?(Hash)
    [args[0..-2], args.last[:default]]
  else
    [args, nil]
  end
end