Java vs Ruby
Forgive me, as this will most likely spark deep seeded hatred from those forced to navigate the deep dark world of Java development. I have managed to break free from it for sometime now, enjoying my Ruby bliss of block passing and metaclasses. Just when I thought I was out, they pull me back in. They, being work. Why can’t we all develop with a language so pointed and terse.
The Java Version
StringBuffer subType = new StringBuffer();
for (String token : tokens) {
// pretty print the tag
char[] c = token.replaceAll("flag", "").toCharArray();
// make first char upper case
if (c.length > 0)
c[0] = Character.toUpperCase(c[0]);
subType.append(c);
}The Prettier, More Compact, Ruby Version
tokens.collect {|t| t.sub(/flag/, '').capitalize }.joinI can hear the snide remarks right now…save them. There are plenty more examples where that came from.
