[BioRuby] Use of NameError versus respond_to?

Andrew Grimm andrew.j.grimm at gmail.com
Fri Jul 1 07:40:04 UTC 2011


This isn't a bug report, just a request for enlightenment.

Why does some of the code use begin ... rescue NameError rather than
respond_to ?

For example, in Bio::Alignment::OriginalPrivate#extract_seq, there's

for m in [ :seq, :naseq, :aaseq ]
  begin
    seq = s.send(m)
  rescue NameError, ArgumentError
    seq = nil
  end
  break if seq
end

Is this because some objects implement seq, naseq or aaseq without
indicating it in respond_to?

Or is this just how code was written back in older times?
https://github.com/bioruby/bioruby/commit/7b26a41e0a515e77d4b7470936b7fbf68a7b09a8
indicates the module was first written back in 2003.

Andrew



More information about the BioRuby mailing list