-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace custom Twitter::NullObject with Naught
- Loading branch information
Showing
5 changed files
with
11 additions
and
112 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
require 'forwardable' | ||
require 'naught' | ||
|
||
module Twitter | ||
class NullObject | ||
extend Forwardable | ||
def_instance_delegators :nil, :nil?, :to_a, :to_c, :to_c, :to_f, :to_h, | ||
:to_i, :to_r, :to_s | ||
alias_method :to_ary, :to_a | ||
alias_method :to_str, :to_s | ||
NullObject = Naught.build do |config| | ||
config.black_hole | ||
config.define_explicit_conversions | ||
config.define_implicit_conversions | ||
config.predicates_return false | ||
|
||
# @return [Twitter::NullObject] This method always returns self. | ||
def method_missing(*args) | ||
self | ||
end | ||
|
||
# @return [TrueClass] This method always returns true. | ||
def respond_to?(method_name, include_private = false) | ||
def nil? | ||
true | ||
end if RUBY_VERSION < '1.9' | ||
|
||
# @return [TrueClass] This method always returns true. | ||
def respond_to_missing?(method_name, include_private = false) | ||
true | ||
end if RUBY_VERSION >= '1.9' | ||
end | ||
end | ||
end |
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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