In talking it over with the co-writer of the Regex-Searching writeup, we think
that with a bit of massaging of the existing code, defining meaningful #reg_desc
methods on Array, Class, Hash, and Object could get a good part of the way there.

>> class Class
>>   alias_method :reg_desc, :name
>>   end
=> Class

>> class Object
>>   def reg_desc
>>     class.reg_desc
>>     end
>>   end
=> nil

>> ObjectRegex.new('Fixnum String+ Regexp?').all_matches([1, 'hi', 2, 3, 4, 'world', 'there', /abc/])
=> [[1, "hi"], [4, "world", "there", /abc/]]

The syntax is a bit restrictive in the current version of object_regex, but I came up with this
quickly for tuple searching:

>> class Array
>>   def reg_desc
>>     'Array_' + map(&:reg_desc).uniq.join('_')+'_'
>>     end
>>   end
=> nil

>> ObjectRegex.new('Array_String_Fixnum_+').match([ ['string', /regex/], ['string2', 1], ['string3', 3], ['string4'] ])
=> [["string2", 1], ["string3", 3]]

I used a cautiously restrictive regex for picking the tokens out of the input pattern, but things like standard generics
syntax (Array<String>) could be possible.

On Jan 31, 2011, at 9:15 PM, Jöòg W Mittag wrote:

> What I *really* would like to see is the union of pattern matching and
> Regexps, ranging over arbitrary types. Unfortunately, I don't have the
> slightest idea what that would like.