Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Extract Options From Args

DZone's Guide to

Extract Options From Args

·
Free Resource
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/
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}