mobj 3.2.2 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/ext/object.rb +37 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjgzNDE0ZTk3M2IwYmY0ZjllYWNiZjU4NGJiZDE3MGQ2ZjFmYTgzMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmNhMDVmYzkxZGUwODBmY2RlNmVlNmJlNWU2YTJlOWQyNTI3MTY3Mg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTM4NWQyYTE0YTgxOWMyMmQ4ZWJhZGUxYjc0NTFlN2YzNmM0MjBiYmExOGFh
|
10
|
+
YjhmMjRlODFhOGUxNGVmNTY5MDUzMzM0MjQwN2IxYzI2NDIxZTM4Y2JjZGRm
|
11
|
+
MTZiMWE5YWU1YjczN2EwYTg0MTMyYTFmM2M5ZDFkOWFjOTc0NDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjY2NmZiMzc5ODc2YmIxOThhNGRjZjIyMWExMzJlOWRhM2ZjNDNmYTc5OTFk
|
14
|
+
MTMwMjIzZmE5ZjhiYmQ1MGYwYjc4Mzg0NDIyMGY1YjczOTg3ZjNjNmFjMGIz
|
15
|
+
NGJmMjg1OGYxMWRjNjZjZWFlN2E3YWEwYTdiY2NhYmNhMTQ4YzU=
|
data/lib/ext/object.rb
CHANGED
@@ -42,12 +42,12 @@ module Mobj
|
|
42
42
|
def h?() a? Hash end
|
43
43
|
def c?() a? Array, Hash end
|
44
44
|
|
45
|
-
def
|
45
|
+
def _?() a? NilClass, FalseClass end
|
46
46
|
|
47
47
|
def z0?() respond_to?(:zero?) ? zero? : f!.zero? end
|
48
48
|
|
49
49
|
def un?()
|
50
|
-
|
50
|
+
_? || (s? && s !~ /\S/) || (c? && mt?) || (n? && z0?)
|
51
51
|
end
|
52
52
|
|
53
53
|
def o?() !un? end
|
@@ -133,25 +133,53 @@ module Mobj
|
|
133
133
|
|
134
134
|
alias_method :ifnil, :try?
|
135
135
|
|
136
|
-
def when
|
136
|
+
def when(val=:noval)
|
137
137
|
iam = self
|
138
|
+
|
139
|
+
return val == self ? self : Forwarder.new do |name, *args, &block|
|
140
|
+
iam.define_singleton_method(:else) { |*vars| self }
|
141
|
+
iam
|
142
|
+
end if val != :noval
|
143
|
+
|
138
144
|
Forwarder.new do |name, *args, &block|
|
139
145
|
if (iam.respond_to?(name) || iam.methods.include?(name)) && (got = iam.__send__(name, *args, &block))
|
140
|
-
thn = Forwarder.new do |name, *
|
146
|
+
thn = Forwarder.new do |name, *inargs, &block|
|
141
147
|
if name.sym == :then
|
142
|
-
|
148
|
+
if block
|
149
|
+
ret = iam.instance_exec(*inargs, &block)
|
150
|
+
ret.define_singleton_method(:else) { |*vars| self }
|
151
|
+
ret
|
152
|
+
elsif inargs.mt?
|
153
|
+
thn
|
154
|
+
else
|
155
|
+
ret = inargs.sequester!
|
156
|
+
ret.define_singleton_method(:else) { |*vars| self }
|
157
|
+
ret
|
158
|
+
end
|
143
159
|
else
|
144
|
-
ret = __send__(name, *
|
145
|
-
ret.define_singleton_method(:else) {
|
160
|
+
ret = __send__(name, *inargs, &block)
|
161
|
+
ret.define_singleton_method(:else) { |*vars, &blk|
|
162
|
+
if vars.mt? && block._?
|
163
|
+
Forwarder.new { ret }
|
164
|
+
else
|
165
|
+
ret
|
166
|
+
end
|
167
|
+
}
|
146
168
|
ret
|
147
169
|
end
|
148
170
|
end
|
149
171
|
else
|
150
172
|
ret = Forwarder.new do |name, *args, &block|
|
151
173
|
if name.sym == :then
|
152
|
-
els = Forwarder.new do |name|
|
174
|
+
els = Forwarder.new do |name, *targs, &block|
|
153
175
|
if name.sym == :else
|
154
|
-
|
176
|
+
if block
|
177
|
+
iam.instance_exec(*targs, &block)
|
178
|
+
elsif targs.mt?
|
179
|
+
Forwarder.new { |name, *eargs, &block| __send__(name, *eargs, &block) }
|
180
|
+
else
|
181
|
+
targs.sequester!
|
182
|
+
end
|
155
183
|
else
|
156
184
|
els
|
157
185
|
end
|