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
44
45
46
47
48
49
50
51
|
# File 'lib/ext/nil.rb', line 44
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
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/ext/nil.rb', line 57
def attempt(value=true)
Forwarder.new do |name, *args, &block|
if self.methods(true).include? name
self.__send__(name, *args, &block)
elsif value.is_a?(Proc)
value.call([name] + args, &block)
elsif value.is_a?(Hash) && value.ki?(name)
value[name].when.is_a?(Proc).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
|
39
40
41
42
|
# File 'lib/ext/nil.rb', line 39
def nil!(*)
@@null = nil
self
end
|
#null! ⇒ Object
Also known as:
try?
34
35
36
37
|
# File 'lib/ext/nil.rb', line 34
def null!(*)
@@null = __mobj__caller
self
end
|
#null? ⇒ Boolean
29
30
31
32
|
# File 'lib/ext/nil.rb', line 29
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
|