Module: Resourceful::OptionsInterpretation
- Included in:
- HttpAccessor
- Defined in:
- lib/resourceful/options_interpretation.rb
Overview
Declarative way of interpreting options hashes
include OptionsInterpretion
def my_method(opts = {})
extract_opts(opts) do |opts|
host = opts.extract(:host)
port = opts.extract(:port, :default => 80) {|p| Integer(p)}
end
end
Defined Under Namespace
Classes: OptionsInterpreter
Instance Method Summary collapse
-
#extract_opts(opts) {|interpeter| ... } ⇒ Object
Interpret an options hash.
Instance Method Details
#extract_opts(opts) {|interpeter| ... } ⇒ Object
Interpret an options hash
22 23 24 25 26 27 28 29 30 |
# File 'lib/resourceful/options_interpretation.rb', line 22 def extract_opts(opts, &blk) opts = opts.clone yield OptionsInterpreter.new(opts) unless opts.empty? raise ArgumentError, "Unrecognized options: #{opts.keys.join(", ")}" end end |