Class: Array
Overview
Array extensions
Instance Method Summary collapse
-
#extract_options! ⇒ Object
Removes and returns the last member of the array if it is a hash.
Instance Method Details
#extract_options! ⇒ Object
Removes and returns the last member of the array if it is a hash. Otherwise, an empty hash is returned This method is useful when writing methods that take an options hash as the last parameter. For example:
def validate_each(*args, &block)
opts = args.extract_options!
...
end
11 12 13 |
# File 'lib/assistance/extract_options.rb', line 11 def last.is_a?(Hash) ? pop : {} end |