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

2008/9/23 Peter A. [email protected]:

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!

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

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…