Ruby = Awesome, this shouldn’t be so easy
This piece of code downloads an RSS feed, drops all the items that match a regular expression, and returns the resulting XML document. And it’s 12 lines of code. Twelve.
require ‘uri’
require ‘rexml/document’
include REXML
url = URI.parse ‘http://blog.paulbetts.org/index.php/feed/’
xml_doc = Document.new Net::HTTP.get_response(url).body
to_delete = []
items = xml_doc.elements[1].elements[1].elements
items.each { |iter| to_delete << iter if /ctags/.match iter.to_s }
to_delete.each { |x| items.delete x }
xml_doc.to_s
I’ve been working on writing an example program (and something I want to use as well!) using everyone’s favorite popular framework, Ruby on Rails. I think that it’s definitely a time-saver, but it has a pretty steep learning curve. While Ruby is extremely flexible with classes, mixins and templates, it makes understanding a framework that uses this trickery like Rails somewhat difficult. The documentation isn’t very clear either, in the sense that there are tons of well-written tutorials, but not many give a high-level overview of the framework (the best I’ve seen is the official book, Agile Web Development with Rails . I think I’m starting to understand it though, and the framework makes adding new features to a site really easy.
