Module: OptionsHash::MethodObject::ClassMethods

Defined in:
lib/options_hash/method_object.rb

Instance Method Summary collapse

Instance Method Details

#call(options = {}) ⇒ Object



14
15
16
# File 'lib/options_hash/method_object.rb', line 14

def call options={}
  new(options).call
end

#option_readers!Object



42
43
44
# File 'lib/options_hash/method_object.rb', line 42

def option_readers!
  options_reader *options.keys
end

#optional(*keys, &block) ⇒ Object



31
32
33
# File 'lib/options_hash/method_object.rb', line 31

def optional *keys, &block
  options.optional *keys, &block
end

#optionsObject



22
23
24
25
# File 'lib/options_hash/method_object.rb', line 22

def options
  @options ||= Class.new(superclass.respond_to?(:options) ?
    superclass.options : OptionsHash)
end

#options_reader(*keys) ⇒ Object



35
36
37
38
39
40
# File 'lib/options_hash/method_object.rb', line 35

def options_reader *keys
  keys.each do |key|
    options.option?(key) or raise KeyError, "#{key} is not an option", caller(2)
    define_method(key){ self.options[key] }
  end
end

#required(*keys, &block) ⇒ Object



27
28
29
# File 'lib/options_hash/method_object.rb', line 27

def required *keys, &block
  options.required *keys, &block
end

#to_procObject



18
19
20
# File 'lib/options_hash/method_object.rb', line 18

def to_proc
  method(:call).to_proc
end