Sha256: f13ae0afcf2a7398a98e4c47f646ffc396ea9d7dc37cbae41cf63928d8163317
Contents?: true
Size: 1.26 KB
Versions: 16
Compression:
Stored size: 1.26 KB
Contents
# = nullclass.rb # # == Copyright (c) 2005 Thomas Sawyer # # Ruby License # # This module is free software. You may use, modify, and/or redistribute this # software under the same terms as Ruby. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. # # == Author(s) # # * Thomas Sawyer # Author:: Thomas Sawyer # Copyright:: Copyright (c) 2005 Thomas Sawyer # License:: Ruby License # = NullClass # # NullClass is essentially NilClass but it differs in one # important way. When a method is called against it that it # deoesn't have, it will simply return null value rather then # raise an error. class NullClass #< NilClass class << self def new @null ||= NullClass.allocate end end def inspect ; 'null' ; end def nil? ; true ; end def null? ; true ; end def [](key); nil; end def method_missing(sym, *args) return nil if sym.to_s[-1,1] == '?' self end end module Kernel def null NullClass.new end end class Object def null? false end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # # TODO =begin #testing =end
Version data entries
16 entries across 16 versions & 1 rubygems