Permalink
Browse files

temp add in of active supports experimental callbacks ... until Rails…

… 3 is out
  • Loading branch information...
1 parent f538e3a commit b30561ca49ed3ce6f924ff0a78341d8c66c77c34 @baccigalupi committed Nov 23, 2009
@@ -0,0 +1,27 @@
+class Array
+ # Wraps the object in an Array unless it's an Array. Converts the
+ # object to an Array using #to_ary if it implements that.
+ def self.wrap(object)
+ if object.nil?
+ []
+ elsif object.respond_to?(:to_ary)
+ object.to_ary
+ else
+ [object]
+ end
+ end
+
+ # 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}
+ def extract_options!
+ last.is_a?(::Hash) ? pop : {}
+ end
+
+end
Oops, something went wrong.

0 comments on commit b30561c

Please sign in to comment.