Module: Pincushion::InstanceMethods
- Defined in:
- lib/pincushion.rb
Overview
module ModuleMethods
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #all?(*preds) ⇒ Boolean
- #all_predicates ⇒ Object
- #all_predicates_hash ⇒ Object
- #any?(*preds) ⇒ Boolean
- #initialize(name, *_) ⇒ Object
- #is(*preds) ⇒ Object
- #is?(predicate) ⇒ Boolean
- #is_not(*preds) ⇒ Object
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
104 105 106 |
# File 'lib/pincushion.rb', line 104 def name @name end |
Instance Method Details
#all?(*preds) ⇒ Boolean
149 150 151 |
# File 'lib/pincushion.rb', line 149 def all?(*preds) preds.all? { |pred| is?(pred) } end |
#all_predicates ⇒ Object
111 112 113 |
# File 'lib/pincushion.rb', line 111 def all_predicates self.class.all_predicates.merge(@additional_predicates) end |
#all_predicates_hash ⇒ Object
115 116 117 |
# File 'lib/pincushion.rb', line 115 def all_predicates_hash all_predicates.map { |p| [p, is?(p)] }.to_h end |
#any?(*preds) ⇒ Boolean
145 146 147 |
# File 'lib/pincushion.rb', line 145 def any?(*preds) preds.any? { |pred| is?(pred) } end |
#initialize(name, *_) ⇒ Object
106 107 108 109 |
# File 'lib/pincushion.rb', line 106 def initialize(name, *_) @name = name @additional_predicates = Set.new end |
#is(*preds) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/pincushion.rb', line 119 def is(*preds) preds.each do |pred| define_singleton_method(:"#{pred}?") { true } @additional_predicates << pred end self end |
#is?(predicate) ⇒ Boolean
137 138 139 140 141 142 143 |
# File 'lib/pincushion.rb', line 137 def is?(predicate) unless all_predicates.include?(predicate) fail MissingPredicateError, "Unknown predicate #{predicate}" end send(:"#{predicate}?") end |
#is_not(*preds) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/pincushion.rb', line 128 def is_not(*preds) preds.each do |pred| define_singleton_method(:"#{pred}?") { false } @additional_predicates << pred end self end |