-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
null_object.rb
66 lines (50 loc) · 1022 Bytes
/
null_object.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'naught'
module Twitter
NullObject = Naught.build do |config| # rubocop:disable Metrics/BlockLength
include Comparable
config.black_hole
config.define_explicit_conversions
config.define_implicit_conversions
config.predicates_return false
def !
true
end
def respond_to?(*)
true
end
def instance_of?(klass)
raise(TypeError, 'class or module required') unless klass.is_a?(Class)
self.class == klass
end
def kind_of?(mod)
raise(TypeError, 'class or module required') unless mod.is_a?(Module)
self.class.ancestors.include?(mod)
end
alias_method :is_a?, :kind_of?
def <=>(other)
if other.is_a?(self.class)
0
else
-1
end
end
def nil?
true
end
def as_json(*)
'null'
end
def to_json(*args)
nil.to_json(*args)
end
def presence
nil
end
def blank?
true
end
def present?
false
end
end
end