Class: Fluidity::Grammer::Base
Instance Method Summary collapse
-
#==(other) ⇒ Object
Have to override the ususal ‘#==` method to support this.
-
#initialize(target, negate = false) ⇒ Base
constructor
A new instance of Base.
-
#method_missing(s, *a, &b) ⇒ Object
private.
Constructor Details
#initialize(target, negate = false) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/fluidity/grammer.rb', line 9 def initialize(target, negate=false) @target = target @negate = negate end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(s, *a, &b) ⇒ Object
private
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fluidity/grammer.rb', line 25 def method_missing(s, *a, &b) if assay = (::Assertion.by_name(s) || ::Assertion.by_operator(s)) if @negate assay.refute!(@target, *a, &b) else assay.assert!(@target, *a, &b) end else q = (s.to_s.end_with?('?') ? s : (s.to_s+'?')) if @target.respond_to?(q) assert(false, "#{q} failed", caller) unless @target.send(q, *a, &b) else super(s, *a, &b) end end end |
Instance Method Details
#==(other) ⇒ Object
Have to override the ususal ‘#==` method to support this.
15 16 17 18 19 20 21 |
# File 'lib/fluidity/grammer.rb', line 15 def ==(other) if @negate ::EqualAssay.refute!(@target, other, :backtrace=>caller) else ::EqualAssay.assert!(@target, other, :backtrace=>caller) end end |