How about this? I have just discovered

pavel@pavel-laptop:~/dev/binexp$ ~/usr/ruby19/bin/irb
irb(main):001:0> /(?<digits>\d+)/ =~ 'abc123def'
=> 3
irb(main):002:0> digits
=> "123"
irb(main):003:0>

According to `ri Regexp#=~`

If =~ is used with a regexp literal with named captures, captured
strings (or nil) is assigned to local variables named by the capture 
names.

  /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ "  x = y  "
  p lhs    #=> "x"
  p rhs    #=> "y"

If it is not matched, nil is assigned for the variables.

  /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ "  x = "
  p lhs    #=> nil
  p rhs    #=> nil

This assignment is implemented in the Ruby parser. The parser detects
'regexp-literal =~ expression' for the assignment. The regexp must be a
literal without interpolation and placed at left hand side.

=======>

It seems Ruby parser can do some magic things!

-- 
Posted via http://www.ruby-forum.com/.