Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/couchrest/support/class.rb
Class Method Summary collapse
-
.wrap(object) ⇒ Object
Wraps the object in an Array unless it’s an Array.
Instance Method Summary collapse
-
#extract_options! ⇒ Object
Extracts options from a set of arguments.
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 (*args)
args.
end
(1, 2) # => {}
(1, 2, :a => :b) # => {:a=>:b}
169 170 171 |
# File 'lib/couchrest/support/class.rb', line 169 def last.is_a?(::Hash) ? pop : {} end |