Class: Vedeu::Options
- Inherits:
-
Object
- Object
- Vedeu::Options
- Defined in:
- lib/vedeu/support/options.rb
Overview
Converts an options Hash into a class containing methods for each of the keys, which when called returns the value associated. When the value is either true or false, an additional predicate method is created.
Instance Attribute Summary collapse
- #_defined ⇒ Array<Symbol> readonly
- #_options ⇒ Hash readonly protected
Class Method Summary collapse
Instance Method Summary collapse
- #_build ⇒ Vedeu::Options
- #_create_alias(alias_name, method_name) ⇒ void private
- #_create_method(name, &block) ⇒ void private
- #initialize(options = {}) ⇒ Vedeu::Options constructor
Constructor Details
#initialize(options = {}) ⇒ Vedeu::Options
20 21 22 23 |
# File 'lib/vedeu/support/options.rb', line 20 def initialize( = {}) = @_defined = [] end |
Instance Attribute Details
#_defined ⇒ Array<Symbol> (readonly)
10 11 12 |
# File 'lib/vedeu/support/options.rb', line 10 def _defined @_defined end |
#_options ⇒ Hash (readonly, protected)
42 43 44 |
# File 'lib/vedeu/support/options.rb', line 42 def end |
Class Method Details
.build(options = {}) ⇒ Vedeu::Options
14 15 16 |
# File 'lib/vedeu/support/options.rb', line 14 def self.build( = {}) new()._build end |
Instance Method Details
#_build ⇒ Vedeu::Options
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vedeu/support/options.rb', line 26 def _build .each do |name, value| _create_method(name) { value } if value.is_a?(TrueClass) || value.is_a?(FalseClass) _create_alias("#{name}?", name) end end self end |
#_create_alias(alias_name, method_name) ⇒ void (private)
This method returns an undefined value.
49 50 51 52 53 |
# File 'lib/vedeu/support/options.rb', line 49 def _create_alias(alias_name, method_name) @_defined << alias_name.to_sym define_singleton_method(alias_name, method(method_name)) end |
#_create_method(name, &block) ⇒ void (private)
This method returns an undefined value.
58 59 60 61 62 |
# File 'lib/vedeu/support/options.rb', line 58 def _create_method(name, &block) @_defined << name.to_sym self.class.send(:define_method, name, &block) end |