DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Extract Options From Args
If we need a method with an arbitrary number of parameters (:arg1, :arg2…) followed by a list of keyword/value options we can use the ActiveSupport method #extract_options! to find the optinons.
def my_method(*args)
options = args.extract_options!
puts "Arguments: #{args.inspect}"
puts "Options: #{options.inspect}"
end
See: http://www.simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/





