This post originated from an RSS feed registered with Web Buzz
by Chris Eidhof.
Original Post: Ruby: Object.with
Feed Title: buzzdriver
Feed URL: http://www.my-website.nl/weblog/feed/
Feed Description: This is a technical weblog about web development, and mainly focussed on markup, css, javascript, semantic web, but also other things like linux, open source and general tech-related subjects.
Ben and I were working on a Ruby on Rails project for Biton, and we’ve built a cool Object.with function. It goes like this:
class Object
def with
yield self
end
end
Resulting in the following (example) code:
Pages.find(1).last_revision.with { ¦r¦
puts r.body
}
I really, really like Ruby!
Tags: ruby, development