mobj 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/ext/object.rb +37 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDY5YjIzNWY0NTZlMGY4NTA0ZmYxOWVjOGQ1ZWFmZjFiMGNlNTdmYw==
4
+ YjgzNDE0ZTk3M2IwYmY0ZjllYWNiZjU4NGJiZDE3MGQ2ZjFmYTgzMA==
5
5
  data.tar.gz: !binary |-
6
- OGI5YWE0MDE4MjA4MDVhNWU2N2E3MzAyZmIyYjUyMTQyNGFmYTYwMQ==
6
+ NmNhMDVmYzkxZGUwODBmY2RlNmVlNmJlNWU2YTJlOWQyNTI3MTY3Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTg2N2QyZjk1NGY1N2Q2NGIzZmE3MmE1MzMxYmViYTlkMGFlN2NkZjUwMzJj
10
- ZjgyYjI4MmM2OTk3MjQwYjMzMWQ0MjgyNTFjZDY5N2QzMzI2OWIzMTMzMzI0
11
- MTllZTM1MmYyN2M3M2E5ZTVkOTE1MGM2OTViZjYwY2ExMGZkYmY=
9
+ NTM4NWQyYTE0YTgxOWMyMmQ4ZWJhZGUxYjc0NTFlN2YzNmM0MjBiYmExOGFh
10
+ YjhmMjRlODFhOGUxNGVmNTY5MDUzMzM0MjQwN2IxYzI2NDIxZTM4Y2JjZGRm
11
+ MTZiMWE5YWU1YjczN2EwYTg0MTMyYTFmM2M5ZDFkOWFjOTc0NDQ=
12
12
  data.tar.gz: !binary |-
13
- ZDZhYTZmNDUyYTg4OGNhNDJiZDlhMGYxNWI2NTI3ZGRmZTc4ZGYwZDYwMDNh
14
- Y2JlZDgzNDVhNDljOGYzMDE4MDlkMTFjNDZmMjA3ZDM5YmZiNWNiY2E0ZmMw
15
- ZjM5N2FlNjlmODVjYzgyNDY3MGU2NGRkYmE5NjQ4YzdiZDRhYzU=
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 x?() a? NilClass, FalseClass end
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
- x? || (s? && s !~ /\S/) || (c? && mt?) || (n? && z0?)
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, *args, &block|
146
+ thn = Forwarder.new do |name, *inargs, &block|
141
147
  if name.sym == :then
142
- thn
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, *args, &block)
145
- ret.define_singleton_method(:else) { Forwarder.new { ret } }
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
- Forwarder.new { |name, *args, &block| __send__(name, *args, &block) }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mason Glaves