Module: Fusu::Array
- Defined in:
- lib/fusu/array.rb
Class Method Summary collapse
-
.extract_options!(ary) ⇒ Object
Extracts options from a set of arguments.
- .wrap(object) ⇒ Object
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 (*args)
args.
end
(1, 2) # => {}
(1, 2, a: :b) # => {:a=>:b}
22 23 24 25 26 27 28 |
# File 'lib/fusu/array.rb', line 22 def self.(ary) if ary.last.is_a?(::Hash) && Fusu::Hash.(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 |