[BioRuby] [GSoC][NeXML and RDF API] Code Review.

Anurag Priyam anurag08priyam at gmail.com
Fri Jul 2 21:07:45 UTC 2010

> I don't understand what you want to do, and how the const_get shorten
> your code. Please show example code.
Taking matrix for example, in each type of Matrix I have defined an add
add_row method which accepts a row which would be of the same kind(
DnaSeqMatrix will take DnaSeqRow ) :

      def add_row( row )
        raise InvalidRowException, "DnaSeqRow expected." unless
row.instance_of? DnaSeqRow
        row_set[ row.id ] = row

If instead I define a add_row method in SeqMatrix like this:

def add_row( row )
  # a DnaSeqMatrix will take a DnaSeqRow
  type = self.class.to_s.sub( /Matrix/, 'Row' )
  klass = NeXML.const_get( type )
  raise InvalidRowException, "#{type} expected." unless row.instance_of?

This way I won't have to define add_row for each sub type of SeqRow.
Similarly for others.

Anurag Priyam,
2nd Year Undergraduate,
Department of Mechanical Engineering,
IIT Kharagpur.

More information about the BioRuby mailing list