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