Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/couchrest/support/class.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap(object) ⇒ Object

Wraps the object in an Array unless it’s an Array. Converts the object to an Array using #to_ary if it implements that.



175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/couchrest/support/class.rb', line 175

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

Instance Method Details

#extract_options!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}


169
170
171
# File 'lib/couchrest/support/class.rb', line 169

def extract_options!
  last.is_a?(::Hash) ? pop : {}
end