From: Joel VanderWerf Date: 2009-04-11T14:22:26+09:00 Subject: Re: a few thoughts for ruby... Roger Pack wrote: > Thought I'd pass these thoughts by the readers here before sending them > to core. They're my current wish list :) > > 1) add an Object#in? method to complement the existing Array#include? It's not really symmetrical. Array has an #include? method because it is a collection. Object has #in? because it is--what? A potential member of a collection? This would conflict with lots of potential other uses of #in? that have nothing to do with collections: Clutch#in? Doctor#in? Fix#in? (to start just with the 0-ary ones). > 2) add some useful lists of exceptions, ex: IO.SELECT_EXCEPTIONS, > IO.READ_EXCEPTIONS, so that you can rescue the wide gamut of them > appropriately, should you desire to. I've wanted that, and ended up with: ALL_NETWORK_ERRORS = [Errno::ECONNRESET, Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::EPIPE, IOError, Errno::ETIMEDOUT] ALL_NETWORK_ERRORS << Errno::EPROTO if defined?(Errno::EPROTO) ALL_NETWORK_ERRORS << Errno::ENETUNREACH if defined?(Errno::ENETUNREACH) Maybe a better way would be to include a module, AnyNetworkError, in each of these. Then you could rescue AnyNetworkError Like this: module E; end class E1 < StandardError; include E; end class E2 < StandardError; include E; end begin raise E1, "foo" rescue E => ex p ex end > 4) (this one's controversial) remove the extra # for code in strings > (i.e. "string#{code}") -> "string{code}" less typing. Would not like having to escape { in strings... -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407