Module: Tins::ExtractLastArgumentOptions

Defined in:
lib/tins/extract_last_argument_options.rb

Overview

Extracts the last argument from an array if it responds to to_hash

This module provides a method to separate arguments into regular arguments and options (a hash) by checking if the last element responds to to_hash

Instance Method Summary collapse

Instance Method Details

#extract_last_argument_optionsArray<Object, Hash>

Extracts the last argument if it responds to to_hash and returns an array with the remaining elements and the extracted options hash.

the extracted options hash

Returns:



12
13
14
15
16
17
18
19
20
21
# File 'lib/tins/extract_last_argument_options.rb', line 12

def extract_last_argument_options
  last_argument = last
  if last_argument.respond_to?(:to_hash) and
    options = last_argument.to_hash.dup
  then
    return self[0..-2], options
  else
    return dup, {}
  end
end