ruby - A good way to check for inclusion of several items in an array -


i have options hash , method update - options hash change , if want tests fail. what's way write this?

raise runtimeerror, msg unless options.keys.include?(   :external_uid,   :display_name,   :country_code ) 

if options.keys doesn't include 3 items, error should raised.

solution almost used (thanks bjhaid):

def ensure_correct_options!(options)   msg = "only 'external_uid', 'display_name' , 'country_code' can "   msg += "updated. given attributes: #{options.keys.inspect}"    raise runtimeerror, msg unless options.keys == [     :external_uid,     :display_name,     :country_code   ] end   

the options have value, write:

unless options[:external_uid] && options[:display_name] && options[:country_code]   raise argumenterror, ":external_uid, :display_name , :country_code required" end 

(i've replaced runtimeerror argumenterror because seems arguments)


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -