Class: NilClass
- Includes:
- Comparable
- Defined in:
- lib/carat/nil-comparable.rb,
lib/carat/nil-missing.rb,
lib/carat-dev/conditional/conditionals.rb
Overview
NilComparable
NilComparable does two things. First it make nil comparable, such that all things (except itself) are greater than it.
Secondly it provides a module called NilComparable to include into any other class to allow it to compare itself to NilClass as the greater of the two.
Author(s)
-
Paul Brannan
-
Thomas Sawyer
Instance Method Summary collapse
- #<=>(x) ⇒ Object (also: #cmp)
- #false? ⇒ Boolean
-
#method_missing(meth, *args) ⇒ Object
Have nil respond to all non-existent methods, always returning
nil
. - #true? ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Have nil respond to all non-existent methods, always returning nil
.
require 'facet/nil/nil_missing'
nil.foo #=> nil
9 10 11 |
# File 'lib/carat/nil-missing.rb', line 9 def method_missing(meth, *args) nil end |
Instance Method Details
#<=>(x) ⇒ Object Also known as: cmp
21 22 23 |
# File 'lib/carat/nil-comparable.rb', line 21 def <=>(x) x.nil? ? 0 : -1 end |
#false? ⇒ Boolean
13 |
# File 'lib/carat-dev/conditional/conditionals.rb', line 13 def false? ; yield ; end |
#true? ⇒ Boolean
14 |
# File 'lib/carat-dev/conditional/conditionals.rb', line 14 def true? ; nil ; end |