Skip to content
Snippets Groups Projects
Unverified Commit b0ccdba1 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Add Object.not_nil?

This method is used to check if an object is _not_ nil, making it the
opposite of Object.nil?. This removes the need for writing
`something.nil?.not`, which reads a bit awkwardly.
parent 60c47568
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -29,4 +29,16 @@ impl Object {
def nil? -> Boolean {
_INKOC.object_equals(self, Nil)
}
# Returns `True` if `self` is any object other than `Nil`.
#
# # Examples
#
# Checking if an object is not `Nil`:
#
# 10.not_nil? # => True
# Nil.not_nil? # => False
def not_nil? -> Boolean {
_INKOC.object_equals(nil?, False)
}
}
Loading
Loading
@@ -94,3 +94,11 @@ test.group('std::object::Object.nil?') do (g) {
assert.false(Object.new.nil?)
}
}
test.group('std::object::Object.not_nil?') do (g) {
g.test('Checking if an object is Nil') {
assert.false(Nil.not_nil?)
assert.true(10.not_nil?)
assert.true(Object.new.not_nil?)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment