Module: Fusu::Array

Defined in:
lib/fusu/array.rb

Class Method Summary collapse

Class Method Details

.extract_options!(ary) ⇒ Object

Extracts options from a set of arguments. Removes and returns the last element in the array if it’s a hash, otherwise returns a blank hash.

def options(*args)
  args.extract_options!
end

options(1, 2)        # => {}
options(1, 2, a: :b) # => {:a=>:b}


22
23
24
25
26
27
28
# File 'lib/fusu/array.rb', line 22

def self.extract_options!(ary)
  if ary.last.is_a?(::Hash) && Fusu::Hash.extractable_options?(ary.last)
    ary.pop
  else
    {}
  end
end

.wrap(object) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/fusu/array.rb', line 3

def self.wrap(object)
  if object.nil?
    []
  elsif object.respond_to?(:to_ary)
    object.to_ary || [object]
  else
    [object]
  end
end