Module: OptionsHash::MethodObject::ClassMethods
- Defined in:
- lib/options_hash/method_object.rb
Instance Method Summary collapse
- #call(options = {}) ⇒ Object
- #option_readers! ⇒ Object
- #optional(*keys, &block) ⇒ Object
- #options ⇒ Object
- #options_reader(*keys) ⇒ Object
- #required(*keys, &block) ⇒ Object
- #to_proc ⇒ Object
Instance Method Details
#call(options = {}) ⇒ Object
14 15 16 |
# File 'lib/options_hash/method_object.rb', line 14 def call ={} new().call end |
#option_readers! ⇒ Object
42 43 44 |
# File 'lib/options_hash/method_object.rb', line 42 def option_readers! *.keys end |
#optional(*keys, &block) ⇒ Object
31 32 33 |
# File 'lib/options_hash/method_object.rb', line 31 def optional *keys, &block .optional *keys, &block end |
#options ⇒ Object
22 23 24 25 |
# File 'lib/options_hash/method_object.rb', line 22 def @options ||= Class.new(superclass.respond_to?(:options) ? superclass. : OptionsHash) end |
#options_reader(*keys) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/options_hash/method_object.rb', line 35 def *keys keys.each do |key| .option?(key) or raise KeyError, "#{key} is not an option", caller(2) define_method(key){ self.[key] } end end |
#required(*keys, &block) ⇒ Object
27 28 29 |
# File 'lib/options_hash/method_object.rb', line 27 def required *keys, &block .required *keys, &block end |
#to_proc ⇒ Object
18 19 20 |
# File 'lib/options_hash/method_object.rb', line 18 def to_proc method(:call).to_proc end |