Class: NilClass
Constant Summary
collapse
- MOBJ_NULL_REGION_BEGIN =
__LINE__
- MOBJ_NULL_REGION_END =
__LINE__
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/ext/nil.rb', line 52
def method_missing(name, *args, &block)
if null?
self
else
nil!
super
end
end
|
Instance Method Details
#__mobj__caller ⇒ Object
6
7
8
9
10
11
|
# File 'lib/ext/nil.rb', line 6
def __mobj__caller()
caller.find do |frame|
(file, line) = frame.split(":")
file != __FILE__ || !(MOBJ_NULL_REGION_BEGIN..MOBJ_NULL_REGION_END).cover?(line.to_i)
end
end
|
#attempt(value = true) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/ext/nil.rb', line 65
def attempt(value=true)
Forwarder.new do |name, *args, &block|
if self.methods(true).include? name
self.__send__(name, *args, &block)
elsif value.p?
value.call([name] + args, &block)
elsif value.h? && value.ki?(name)
value[name].when.p?.call(*args, &block)
else
value
end
end
end
|
#fals?(val = nil, &block) ⇒ Boolean
21
22
23
24
25
26
27
|
# File 'lib/ext/nil.rb', line 21
def fals?(val=nil, &block)
if block
block.call(val)
else
val
end
end
|
#iff?(_ = nil) ⇒ Boolean
29
30
31
|
# File 'lib/ext/nil.rb', line 29
def iff?(_=nil)
self
end
|
#iffn?(value = nil, &block) ⇒ Boolean
33
34
35
|
# File 'lib/ext/nil.rb', line 33
def iffn?(value = nil, &block)
block ? instance_exec(value, &block) : value
end
|
47
48
49
50
|
# File 'lib/ext/nil.rb', line 47
def nil!(*)
@@null = nil
self
end
|
#null! ⇒ Object
Also known as:
try?
42
43
44
45
|
# File 'lib/ext/nil.rb', line 42
def null!(*)
@@null = __mobj__caller
self
end
|
#null? ⇒ Boolean
37
38
39
40
|
# File 'lib/ext/nil.rb', line 37
def null?(*)
@@null ||= nil
@@null && @@null == __mobj__caller
end
|
#tru?(_ = nil, f = nil, &block) ⇒ Boolean
17
18
19
|
# File 'lib/ext/nil.rb', line 17
def tru?(_=nil, f=nil, &block)
f
end
|
#zero? ⇒ Boolean
13
14
15
|
# File 'lib/ext/nil.rb', line 13
def zero?
true
end
|