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.
132 133 134 |
# File 'lib/pincushion.rb', line 132 def name @name end |
Instance Method Details
#all?(*preds) ⇒ Boolean
177 178 179 |
# File 'lib/pincushion.rb', line 177 def all?(*preds) preds.all? { |pred| is?(pred) } end |
#all_predicates ⇒ Object
139 140 141 |
# File 'lib/pincushion.rb', line 139 def all_predicates self.class.all_predicates.merge(@additional_predicates) end |
#all_predicates_hash ⇒ Object
143 144 145 |
# File 'lib/pincushion.rb', line 143 def all_predicates_hash all_predicates.map { |p| [p, is?(p)] }.to_h end |
#any?(*preds) ⇒ Boolean
173 174 175 |
# File 'lib/pincushion.rb', line 173 def any?(*preds) preds.any? { |pred| is?(pred) } end |
#initialize(name, *_) ⇒ Object
134 135 136 137 |
# File 'lib/pincushion.rb', line 134 def initialize(name, *_) @name = name @additional_predicates = Set.new end |
#is(*preds) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/pincushion.rb', line 147 def is(*preds) preds.each do |pred| define_singleton_method(:"#{pred}?") { true } @additional_predicates << pred end self end |
#is?(predicate) ⇒ Boolean
165 166 167 168 169 170 171 |
# File 'lib/pincushion.rb', line 165 def is?(predicate) unless all_predicates.include?(predicate) fail MissingPredicateError, "Unknown predicate #{predicate}" end send(:"#{predicate}?") end |
#is_not(*preds) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'lib/pincushion.rb', line 156 def is_not(*preds) preds.each do |pred| define_singleton_method(:"#{pred}?") { false } @additional_predicates << pred end self end |