Dynamic method definition in ruby
===

What does `$1.to_sym => args[0]` and `($1.to_sym,*args,&block)` do in the following line of code?

    class Table
      def method_missing(id,*args,&block)
        return as($1.to_sym,*args,&block) if id.to_s =~ /^to_(.*)/
        return rows_with($1.to_sym => args[0]) if id.to_s =~ /^rows_with_(.*)/
        super
      end
      # ...
    end

**Context:**  
Ruport is a Ruby reporting library. You can use the Ruport::Data::Table class to create tabular data and convert it to different formats—text, for example:  

    require 'ruport'  
    table = Ruport::Data::Table.new :column_names => ["country" , "wine" ], :data => [["France" , "Bordeaux" ], ["Italy" , "Chianti" ], ["France" , "Chablis" ]]  
    puts table.to_text

    ⇒    
    +--------------------+
    | country |   wine   |
    +--------------------+
    | France | Bordeaux |
    | Italy  | Chianti |
    | France | Chablis |
    +--------------------+

Let’s say you select only the French wines and convert them to comma-separated values:

    found = table.rows_with_country("France" )
    found.each do |row|
      puts row.to_csv
    end

    ⇒
    France, Bordeaux
    France, Chablis

What you just did is call a method named rows_with_country( ) on Ruport::Data::Table. But how could the author of this class know you were going to have a column named country? The fact is, the author didn’t know that. If you look inside Ruport, you see that both rows_with_country( ) and to_csv( ) are Ghost Methods. The Ruport::Data::Table class is somewhat as defined above.  

A call to rows_with_country( ) becomes a call to a more traditional-looking
method, rows_with(:country), which takes the column name as an argu-
ment. Also, a call to to_csv( ) becomes a call to as(:csv). If the method
name doesn’t start with either of these two prefixes, Ruport falls back
to Kernel#method_missing( ), which throws a NoMethodError. (That’s what
the super keyword is for.)