Class: Array
Instance Method Summary collapse
-
#assert_length!(length, name = nil) ⇒ self
Checks that the Array matches a given length, and returns the Array unmodified.
-
#refute_length!(length, name = nil) ⇒ self
Checks that the Array does not match a given length, and returns the Array unmodified.
Instance Method Details
#assert_length!(length, name = nil) ⇒ self
Checks that the Array matches a given length, and returns the Array unmodified. If the Array fails this check, an exception is raised.
24 25 26 27 28 29 30 31 |
# File 'lib/mini_sanity/array.rb', line 24 def assert_length!(length, name = nil) if !(length === self.length) raise MiniSanity::Error.new(name, "#{self.class} having #{length} elements", self.inspect) end self end |
#refute_length!(length, name = nil) ⇒ self
Checks that the Array does not match a given length, and returns the Array unmodified. If the Array fails this check, an exception is raised.
54 55 56 57 58 59 60 61 |
# File 'lib/mini_sanity/array.rb', line 54 def refute_length!(length, name = nil) if length === self.length raise MiniSanity::Error.new(name, "#{self.class} not having #{length} elements", self.inspect) end self end |