Ruby: Something in Nothing
Straight Nil
In the Ruby language everything is an object. This includes Nil, which is stands for nothing, but isn’t really nothing, because as an object Nil can have methods called upon it. To check if something has the value of nil
, we can called a method called #nil?
upon it.
Nil class also has several other methods such as #to_a
, #to_h
, #to_f
, #to_i
and #to_s
. This converts a nil value into other data-types in the following ways:
The #empty?
Method
When an Array, Hash or Strings length is equal to 0
, i.e. it has no elements, it is called empty. The #empty?
method returns a boolean value as to whether or not this is the case. For instance: