Module: Assay::Bang::Methods
- Included in:
- Object
- Defined in:
- lib/assay/bang.rb
Overview
Included into Object.
Instance Method Summary collapse
-
#method_missing(method_name, *args, &block) ⇒ Object
Handle
foo!andnot_foo!by way of an assay class or the object's ownfoo?. - #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Handle foo! and not_foo! by way of an assay class or the
object's own foo?.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/assay/bang.rb', line 67 def method_missing(method_name, *args, &block) name, negate = ::Assay::Bang.parse(method_name) return super unless name if assay = ::Assay::Bang.lookup(name) if negate assay.refute!(self, *args, {:backtrace=>caller}, &block) else assay.assert!(self, *args, {:backtrace=>caller}, &block) end elsif respond_to?("#{name}?") truth = __send__("#{name}?", *args, &block) call = "#{inspect}.#{name}?" call += "(#{args.map{ |a| a.inspect }.join(', ')})" unless args.empty? if negate ::Kernel.refute(truth, ::Assertion, "! #{call}", caller) else ::Kernel.assert(truth, ::Assertion, call, caller) end else super end end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
93 94 95 96 97 98 99 100 |
# File 'lib/assay/bang.rb', line 93 def respond_to_missing?(method_name, include_private=false) name, _ = ::Assay::Bang.parse(method_name) if name && (::Assay::Bang.lookup(name) || respond_to?("#{name}?")) true else super end end |