hoodwink.d enhanced


Sharing Ruby and Python Exceptions #

by why in inspect

If you’re coming from Python and using Ruby now (or straddling the both,) you might relate to Jonas Galvez, who prefers the Liberal Feed Parser when parsing RSS and is calling it from Ruby. The sly part is that he’s passing back exceptions to Ruby in YAML. He’s just got a file that defines error codes and his classes are trained to turn those codes into exceptions.

 ERROR_CODES = YAML::load open("config/errorcodes.yml").read

 module MyExceptions
   class MyException < StandardError
   CODES = []
   for k, v in ERROR_CODES
     CODES[v['code']] = const_set(k, Class.new(MyException) {
       define_method :to_s do
         "{code: #{v['code']}, message: #{v['message']}}" 

Not bad at all. I’ll bet you guys will put arms on this thing. A bit more than to_s needs to be defined, I guess. Anyway, touch it, it’s real.

said on 26 Oct 2005 at 11:19

Aww, I’m hurt. FeedTools has been snubbed.

No really, I’m gonna cry, even if it is true that the snaky parser is still slightly more polished than my rocky red variant.

(But not for long!)

said on 27 Oct 2005 at 04:45

Perhaps a bit more than to_s: handgranat.se/lab/ruby/bytestream.rb

Comments are closed for this entry.