module Bang::MethodMissing
Mixin of Object
class, will take any undefined bang method, e.g. ‘foo!` and if there is a corresponding query method, e.g. `foo?`, then it will utilize the query method to make an assertion.
Public Instance Methods
method_missing(s, *a, &b)
click to toggle source
If missing method is a bang method, see if there is a corresponding query method and use that to make an assertion. Will also recognize the same prefixed by ‘not_`, e.g. `not_equal_to?`.
Calls superclass method
# File lib/bang.rb, line 73 def method_missing(s, *a, &b) return super(s, *a, &b) unless s.to_s.end_with?('!') neg = false name = s.to_s.chomp('!') if name.start_with?('not_') neg = true name = name[4..-1] end meth = method("#{name}?") rescue nil return super(s, *a, &b) unless meth result = meth.call(*a, &b) if neg refute(result, Bang::Assertion.piece(s, a, b, caller)) else assert(result, Bang::Assertion.piece(s, a, b, caller)) end end