fsteeg.com | notes | tags
∞ /notes/ruby-iterators | 2005-10-13 | ruby
Cross-posted to: https://fsteeg.wordpress.com/2005/10/13/ruby-iterator/
An example for the higher-level, more problem-oriented things you can do with Ruby's iterators. In Java, I just tried to do this to insert blanks into all words written entirely in uppercase:s.replaceAll("\\b([A-Z]+)\\b","$1".replaceAll("([A-Z])","$1"+" "));
s.gsub(/\b([A-Z]+)\b/){$1.gsub(/([A-Z])/){$1+" "}}
s.gsub(/\b([A-Z]+)\b/){$1.split("").join(" ")}