Top Level Namespace
Defined Under Namespace
Modules: Kernel, Vapir, Waiter Classes: Hash, Module, String, Symbol, WaiterError
Constant Summary collapse
Instance Method Summary collapse
-
#handle_options(given_options, default_options, other_allowed_keys = []) ⇒ Object
takes given options and default options, and optionally a list of additional allowed keys not specified in default options (this is useful when you want to pass options along to another function but don’t want to specify a default that will clobber that function’s default) raises ArgumentError if the given options have an invalid key (defined as one not specified in default options or other_allowed_keys), and sets default values in given options where nothing is set.
Instance Method Details
#handle_options(given_options, default_options, other_allowed_keys = []) ⇒ Object
takes given options and default options, and optionally a list of additional allowed keys not specified in default options (this is useful when you want to pass options along to another function but don’t want to specify a default that will clobber that function’s default) raises ArgumentError if the given options have an invalid key (defined as one not specified in default options or other_allowed_keys), and sets default values in given options where nothing is set.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/vapir-common/handle_options.rb', line 6 def (, , other_allowed_keys=[]) =.dup unless (unknown_keys=(.keys-.keys-other_allowed_keys)).empty? raise ArgumentError, "Unknown options: #{unknown_keys.map(&:inspect).join(', ')}. Known options are #{(.keys+other_allowed_keys).uniq.map(&:inspect).join(', ')}" end (.keys-.keys).each do |key| [key]=[key] end end |