Shortcut for "if options.key?(:full)"?

If I pass an options hash into a def, how do I easily check to see if an
option is set? This is how I'm doing it now:

if options.key?(:some_option)
   ...
end

Knowing Ruby, there's got to be a cleaner/better way!

Pete

···

--
Posted via http://www.ruby-forum.com/.

If nil is not used as valid option value you can usually do

if options[:some_option]

I don't see how it can become much shorter - unless you rename
"options" and options.

Cheers

robert

···

2008/9/23 Peter Alvin <form@awebabove.com>:

If I pass an options hash into a def, how do I easily check to see if an
option is set? This is how I'm doing it now:

if options.key?(:some_option)
  ...
end

Knowing Ruby, there's got to be a cleaner/better way!

--
use.inject do |as, often| as.you_can - without end

if options.key?(:some_option)
   ...
end

Knowing Ruby, there's got to be a cleaner/better way!

You can generally use options.fetch(:some_option, default) to pass a default thru without any 'if' statements...