Class: MustAssertions
- Inherits:
- BasicObject
- Defined in:
- lib/ruby_ext/core/must.rb
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
Class Method Summary collapse
Instance Method Summary collapse
- #<(o) ⇒ Object
- #<=(o) ⇒ Object
- #==(o) ⇒ Object
- #=~(o) ⇒ Object
- #>(o) ⇒ Object
- #>=(o) ⇒ Object
- #a(*args) ⇒ Object (also: #an)
- #be ⇒ Object
- #blank ⇒ Object
- #defined ⇒ Object
- #empty ⇒ Object
- #exist(*args) ⇒ Object
- #false ⇒ Object
- #have ⇒ Object
- #in(*args) ⇒ Object
-
#include(o) ⇒ Object
def be klass = nil if klass.class == Array klass.any?{|k| @obj.respond_to :is?, k} else @obj.respond_to :is?, klass end end.
-
#initialize(obj) ⇒ MustAssertions
constructor
A new instance of MustAssertions.
- #never_called ⇒ Object
- #nil ⇒ Object
- #present ⇒ Object
- #respond_to(method) ⇒ Object
- #true ⇒ Object
Constructor Details
#initialize(obj) ⇒ MustAssertions
Returns a new instance of MustAssertions.
6 7 8 |
# File 'lib/ruby_ext/core/must.rb', line 6 def initialize obj @obj = obj end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
4 5 6 |
# File 'lib/ruby_ext/core/must.rb', line 4 def obj @obj end |
Class Method Details
.assertions ⇒ Object
118 119 120 121 |
# File 'lib/ruby_ext/core/must.rb', line 118 def self.assertions special = [:be, :have] public_instance_methods.select{|m| m !~ /^__/ and !special.include?(m)} end |
Instance Method Details
#<(o) ⇒ Object
92 93 94 |
# File 'lib/ruby_ext/core/must.rb', line 92 def < o @obj < o end |
#<=(o) ⇒ Object
100 101 102 |
# File 'lib/ruby_ext/core/must.rb', line 100 def <= o @obj <= o end |
#==(o) ⇒ Object
10 11 12 |
# File 'lib/ruby_ext/core/must.rb', line 10 def == o @obj == o end |
#=~(o) ⇒ Object
14 15 16 |
# File 'lib/ruby_ext/core/must.rb', line 14 def =~ o @obj =~ o end |
#>(o) ⇒ Object
88 89 90 |
# File 'lib/ruby_ext/core/must.rb', line 88 def > o @obj > o end |
#>=(o) ⇒ Object
96 97 98 |
# File 'lib/ruby_ext/core/must.rb', line 96 def >= o @obj >= o end |
#a(*args) ⇒ Object Also known as: an
34 35 36 37 38 39 40 |
# File 'lib/ruby_ext/core/must.rb', line 34 def a *args if args.class == ::Array args.any?{|k| @obj.is_a? k} else @obj.is_a? args end end |
#be ⇒ Object
108 109 110 111 |
# File 'lib/ruby_ext/core/must.rb', line 108 def be @prefix = 'be' self end |
#blank ⇒ Object
80 81 82 |
# File 'lib/ruby_ext/core/must.rb', line 80 def blank @obj.blank? end |
#defined ⇒ Object
26 27 28 |
# File 'lib/ruby_ext/core/must.rb', line 26 def defined @obj != nil end |
#empty ⇒ Object
76 77 78 |
# File 'lib/ruby_ext/core/must.rb', line 76 def empty @obj.empty? end |
#exist(*args) ⇒ Object
104 105 106 |
# File 'lib/ruby_ext/core/must.rb', line 104 def exist *args @obj.exist? *args end |
#false ⇒ Object
72 73 74 |
# File 'lib/ruby_ext/core/must.rb', line 72 def false !@obj end |
#have ⇒ Object
113 114 115 116 |
# File 'lib/ruby_ext/core/must.rb', line 113 def have @prefix = 'have' self end |
#in(*args) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_ext/core/must.rb', line 55 def in *args if args.size == 1 obj = args.first if obj.is_a?(::Array) or obj.is_a?(::Range) obj.include? @obj else args.include? @obj end else args.include? @obj end end |
#include(o) ⇒ Object
def be klass = nil
if klass.class == Array
klass.any?{|k| @obj.respond_to :is?, k}
else
@obj.respond_to :is?, klass
end
end
51 52 53 |
# File 'lib/ruby_ext/core/must.rb', line 51 def include o @obj.include? o end |
#never_called ⇒ Object
18 19 20 |
# File 'lib/ruby_ext/core/must.rb', line 18 def never_called false end |
#nil ⇒ Object
22 23 24 |
# File 'lib/ruby_ext/core/must.rb', line 22 def nil @obj.equal? nil end |
#present ⇒ Object
84 85 86 |
# File 'lib/ruby_ext/core/must.rb', line 84 def present !@obj.blank? end |
#respond_to(method) ⇒ Object
30 31 32 |
# File 'lib/ruby_ext/core/must.rb', line 30 def respond_to method @obj.respond_to? method end |
#true ⇒ Object
68 69 70 |
# File 'lib/ruby_ext/core/must.rb', line 68 def true !!@obj end |