Reg 0.4.8 Released

Reg version 0.4.8 has been released!

Reg is a library for pattern matching in ruby data structures. Reg
Regexp-like match and match-and-replace for all data structures
Arrays, Objects, and Hashes), not just Strings.

Reg is best thought of in analogy to regular expressions; Regexps are
data structures for matching Strings; Regs are special data structures
matching ANY type of ruby data (Strings included, using Regexps).

== Installation:

Type this command to install the gem:
gem install reg
Or, download the tarball from rubyforge:

For more complete documentation, see:

== Examples:

“… the effect of drinking a Pan Galactic Gargle Blaster is like
your brains smashed out by a slice of lemon wrapped round a large gold
– Douglas Adams, Hitchhiker’s_Guide_to_the_Galaxy

Reg is kind of hard to bend your brain around, so here are some

Matches array containing exactly 2 elements; 1st is another array, 2nd

Like above, but 1st is array of arrays of symbol

Matches array of at least 3 consecutive symbols and nothing else:

Matches array with at least 3 symbols in it somewhere:
+[OBS, Symbol+3, OBS]

Matches array of at most 6 strings starting with ‘g’
+[/^g/-6] #no .reg necessary for regexp

Matches array of between 5 and 9 hashes containing a key :k pointing to
something non-nil:
+[ +{:k=>~nil.reg}*(5…9) ]

Matches an object with Integer instance variable @k and property (ie
foobar that returns a string with ‘baz’ somewhere in it:
-{:@k=>Integer, :foobar=>/baz/}

Matches array of 6 hashes with 6 as a value of every key, followed by
18 objects with an attribute @s which is a String:
+[ +{OB=>6}*6, -{:@s=>String}*18 ]

Matches a single item whose method ‘length’ returns a Fixnum:
item_that.length.is_a? Fixnum

Here’s an example of a Reg::Knows matcher, which matches objects that
have the
#slice method:

== Changes:

0.4.8 / 21dec2009

  • 2 Major Bugfixes:
    • ported to ruby 1.9
    • dropped Cursor dependancy in favor of Sequence
  • 2 Minor Bugfixes:
    • fixed empty array matcher matching non-empty arrays
    • actually handle the case of non-present rubygems.rb correctly