EventMachine: Get Excited By Scalable Non-Blocking I/O »
Created at: 19.03.2010 02:36, source: Ruby Inside, tagged: Cool Tutorials
EventMachine is a simple(ish), fast, event-driven I/O library for Ruby. Its goal is to provide highly scalable I/O performance with an easy-to-use API wrapped around the nastiest parts of the process (since typical Ruby coding practices aren't particularly event-driven friendly). Aman Gupta has put together an awesome 114-page deck of slides (also available as a PDF) that walks through EventMachine with lots of practical code examples.
The presentation walks through:
- Who uses EventMachine (a lot of big guys - Heroku, GitHub, 37signals, Engine Yard, PostRank)
- What EventMachine is good for
- Ruby's other I/O solutions (and why they suck)
- What a "reactor" is
- How to write asychronous code with EventMachine's API
- How EventMachine provides event-compatible iterators and timers
- EventMachine's message channels
Even though Aman's slides are meant to go alongside a live presentation, they stand well on their own and provide more than enough incentive to check out EventMachine is event-driven I/O is something that would benefit you, so stop reading this post and get flicking through Aman's awesome slides!
more »
Building A Well Formed Number Handling Class From Scratch »
Created at: 25.02.2010 03:21, source: Ruby Inside, tagged: Ruby Tricks Tutorials
Over on the Ruby Best Practices blog,
Robert Klemme walks through the process of building a new numeric class from scratch in Ruby - taking into account all the gotchas and considerations that pop up along the way. Robert's task is harder and more involved than you'd initially suspect.!
Robert chooses to build a HexNum class that can represent integers that are then displayed as hex numbers. There are considerations to be made with handling conversions from existing numeric types and his new HexNum class, conversions to other types, supporting standard comparison methods, and overloading.
All of the above concerns are covered in the post with all the quality and detail you should expect from the RBP blog by now. This post in particular should prove interesting to most Ruby developers who feel happy digging deep (no, this isn't an article for beginners!).
[job] BeenVerified.com is currently looking for a Ruby and Rails developer to join their team in New York City. Alternatively, check out one of the other 12 jobs on our Ruby jobs board!
more »
How Ruby Manages Memory and Garbage Collection »
Created at: 24.02.2010 02:33, source: Ruby Inside, tagged: Elsewhere Tutorials
Garbage Collection and the Ruby Heap is a presentation given by Joe Damato and Aman Gupta at the recent LA Ruby Conference. You only get the slides for now (all 70 of them!), but they're very detailed and can almost work as a standalone concise e-book on Ruby's garbage collection system.
Joe and Aman take a look at C memory management vs Ruby and show the difference between the stack and the heap. As a garbage collected language, Ruby takes the easy route by putting everything on the heap and the presentation demonstrates how the MRI (Matz's Ruby 1.8) does this, as well as how objects are tracked within memory (right down to the underlying C structs).

MRI's garbage collection scheme isn't particularly well optimized (though Phusion's Ruby Enterprise Edition has made some tweaks) and the presentation demonstrates the viability of some other garbage collection schemes (as always, the issue is compatibility with native extensions).
The presentation finishes off with a interesting walkthrough of using memprof (a Ruby memory profiler) to debug a memory leak in Rails 3.
[e-book] The Rails 3 Upgrade Handbook by Jeremy McAnally is a 120 page guide on migrating your apps from Rails 2.x to Rails 3.0. There's a review of it on Rails Inside if you want to learn more.
more »
Deploy A Free, Ruby Powered Blog In 5 Minutes with Toto and Heroku »
Created at: 05.02.2010 22:22, source: Ruby Inside, tagged: Cool Tutorials
Toto (GitHub repo) is a new lightweight Ruby and Rack-based blogging engine designed specifically for "hackers" by Alexis Sellier. Content is managed entirely through Git - so everything is version controlled - and articles are stored as text files with embedded YAML metadata. At only 300 lines, it's easy to hack to your own taste, too.
Alexis has decided to push Toto by demonstrating how easy it is to deploy - for free - on the Heroku platform. You can literally get a blog up on Heroku within 5 minutes, even if you haven't already got a Heroku account (I just tried it).
How To Do It
Here are the basic steps:
- Sign up for an account at Heroku.com - all you have to do is provide an e-mail address, validate it, then enter a password.
gem install herokugit clone git://github.com/cloudhead/dorothy.git your-blog-dir- cd your-blog-dir
heroku create- Use the URL returned by
heroku createand add a line in to theToto::Server.newblock inconfig.rulike:set :url, 'http://your.heroku.url.here' - git commit -am "Added URL"
- git push heroku master
- You're live!
It's that simple - I just tried it (see http://furious-fire-87.heroku.com for a live demo)! Beyond this stage, you need to check out Toto's documentation and actually add some posts to your Toto install, customize the template, and what not.
If you're interested in lightweight systems like Toto, check out Scanty and Jekyll (which includes a blog-like system but at heart is designed to cope with full sites).
more »
Rails 3.0’s ActiveModel: How To Give Ruby Classes Some ActiveRecord Magic »
Created at: 13.01.2010 18:46, source: Ruby Inside, tagged: Cool Ruby on Rails Tutorials
One of the biggest benefits of bringing Merb developer Yehuda Katz on board to work on Rails 3.0 has been his relentless pursuit of extracting out all of Rails' magical abilities from their monolithic encasings and into separate, manageable chunks. A case in point is ActiveModel, a new library that provides the model related parts of ActiveRecord but without the database requirements.
Get Rails-like Model Behavior on Any Ruby Class
In extracting the model-building parts of ActiveRecord, ActiveModel makes it possible to add model-like behavior to any Ruby class, with no Rails or databases required. In his latest blog post, ActiveModel: Make Any Ruby Object Feel Like ActiveRecord, Yehuda shows off how to get Rails-style models with validations, serialization, callbacks, dirty tracking, internationalization, attributes, observers and all the other Rails goodness.
Example Code
I've taken Yehuda's main example of using ActiveModel on a non Rails class and extended it with some code that actually uses the model:
require 'active_model' class Person include ActiveModel::Validations validates_presence_of :first_name, :last_name attr_accessor :first_name, :last_name def initialize(first_name, last_name) @first_name, @last_name = first_name, last_name end end a = Person.new("Fred", nil) a.valid? # => false a.last_name = "Flintstone" a.valid? # => true
Installing ActiveModel
If you're interested in ActiveModel and not so much in Rails 3.0, installing it is reasonably easy (though not as easy as only installing a gem just as yet):
- Go to or make a temporary directory
git clone git://github.com/rails/rails.gitcd railsrake gemgem install activesupport/pkg/activesupport-3.0.pre.gemgem install activemodel/pkg/activemodel-3.0.pre.gem
Once this is all done, the code example above will work.
As an aside, if you fancy having a go with the full pre-release (a.k.a. "pre") version of Rails 3.0, check out Dr Nic's slightly out of date but otherwise useful guide.
more »
