From: Roger Pack Date: 2009-04-11T15:30:54+09:00 Subject: Re: a few thoughts for ruby... Thanks for the reply Joel. >> 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? Yeah. I'm not saying it's symmetric as much as useful and intuitive--some of the big reasons I like Ruby :) Would #within? be better? > 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) Looks like it would indeed be useful--especially for cross platform where you 'wish you didnt have to know them all for every platform' (there really are a lot of them -- see http://betterlogic.com/roger/?p=1223 as an example). > Maybe a better way would be to include a module, AnyNetworkError, in > each of these. Then you could... Yeah, or have them all descend from a single ancestor. I would say just descend from SocketError except that SocketError is actually raised as an exception itself, every so often, so it has its own meaning currently...though I guess that doesn't stop it from being an ancestor. > module E; end ... > begin > raise E1, "foo" > rescue E => ex > p ex > end That's pretty elegant. With an array you can [non intuitively] also get by: > begin > raise SocketError "foo" > rescue *ALL_NETWORK_ERRORS => ex > p ex > end (I'm sure you knew that). >> 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... Ok. This next isn't meant as an attacking question but...do you use { in normal strings often? Granted probably more than #, but...? Thanks! -=r -- Posted via http://www.ruby-forum.com/.