Created
March 31, 2015 01:09
-
-
Save warmwaffles/e5b3e03395cff4512e0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A basic null object that can be used in place of a `nil`. | |
| class NullObject | |
| def initialize(*); end | |
| def method_missing(*); self; end | |
| def respond_to?(*); true; end | |
| def to_s; ''; end | |
| def to_str; ''; end | |
| def to_i; 0; end | |
| def to_f; 0.0; end | |
| def to_c; 0.to_c; end | |
| def to_r; 0.to_r; end | |
| def to_a; []; end | |
| def to_ary; []; end | |
| def to_h; {}; end | |
| def nil?; true; end | |
| def present?; false; end | |
| def persisted?; false; end | |
| def empty?; true; end | |
| def blank?; true; end | |
| def !; true; end | |
| def tap | |
| yield(self) | |
| self | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment