mobj 1.6.7 → 1.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mobj.rb +23 -5
  2. metadata +2 -2
@@ -238,11 +238,19 @@ module Mobj
238
238
  if path == :* || obj.nil?
239
239
  obj
240
240
  elsif obj.is_a?(Array)
241
- obj.map { |o| extract(o, path) }
241
+ if path[0] == '*' && obj.respond_to?(path[1..-1].sym)
242
+ obj.__send__(path[1..-1].sym)
243
+ else
244
+ obj.map { |o| extract(o, path) }
245
+ end
242
246
  elsif path.is_a?(Array)
243
247
  path.map { |pth| obj[pth.sym] }
244
- else
248
+ elsif obj.respond_to?(path.sym)
249
+ obj.__send__(path.sym)
250
+ elsif obj.respond_to? :[]
245
251
  obj[path.sym]
252
+ else
253
+ nil
246
254
  end
247
255
  end
248
256
 
@@ -291,8 +299,18 @@ module Mobj
291
299
  end
292
300
 
293
301
  class ::String
294
- def ~@() "~#{self}" end
295
- def -@() "^.#{self}" end
302
+
303
+ def matches(regexp, &block)
304
+ start = 0
305
+ while (match = match(regexp, start))
306
+ start = match.end(0)
307
+ block.call(match)
308
+ end
309
+ end
310
+
311
+ def walk(obj)
312
+ tokenize.walk(obj)
313
+ end
296
314
 
297
315
  def tokenize
298
316
  tokens = []
@@ -331,7 +349,7 @@ module Mobj
331
349
  end
332
350
  end
333
351
  end
334
- tokens.size == 1 ? tokens.first : Token.new(:root, tokens)
352
+ tokens = tokens.size == 1 ? tokens.first : Token.new(:root, tokens)
335
353
  end
336
354
  end
337
355
 
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: 1.6.7
4
+ version: 1.6.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec