Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Interesting Ruby Tidbits That Don’t Need Separate Posts #18

By Peter Cooper / March 1, 2008

MacRuby: Ruby Running On Top of Objective-C

Most Mac-based Ruby developers are already familiar with RubyCocoa, a bridge that enables regular Ruby apps to talk to OS X's various frameworks. MacRuby, however, takes a rather different approach and is a port of Ruby 1.9 that runs directly on the Objective-C runtime and garbage collector. It's still in its early stages, but for anyone interested in Ruby implementations, this is worth a look.

Try: Stop Using "@person ? @person.name : nil" And Start Using "@person.try(:name)"

try() is a ridiculously simple, but incredibly useful, bit of sugar Chris Wanstrath has come up with for making it easy to "try" and call methods on objects, but without Ruby getting upset if that method doesn't exist.

ProcessorPool: Easily Farm Work to Amazon EC2 Instances

And the Rubyist infatuation with Amazon's EC2 service continues! Ari Lerner and Ron Evans have developed ProcessorPool, a new Ruby library that provides a simple load-balancing solution for Amazon's EC2 and S3 backend. It allows you to "effortlessly farm work to an EC2 instance." The best source of information is Ari's own blog post where some demonstration code is shown.

Heroku Gits an API

Heroku, the much heralded Ruby on Rails online development and deployment platform, has launched an API along with external Git access. The combination of these new features mean that you can work on your Rails applications on your local machine and deploy them on Heroku with just a few simple steps. All you need to do is install the Heroku gem, then use the "heroku" command line app to create an application before finally pushing it back to the Heroku servers with git. Miraculously, pushing your code back to Heroku automatically runs the migrations and restarts the processors on the server. One step deployment!

Comments

  1. Fred says:

    Wow, Heroku really rocks.

  2. dubek says:

    Regarding Chris Wanstrath's try(), I'd at least allow it to accept methods that need arguments, so:

    class Object
    def try(method, *args)
    send(method, *args) if respond_to? method
    end
    end

  3. ic9 says:

    Instead of the try(:name),
    http://blog.rubyenrails.nl/articles/2008/02/29/our-daily-method-18-nilclass-method_missing

  4. Trans says:

    I would suggest:

    ##
    # @person ? @person.name : nil
    # vs
    # @person.try(:name)
    def try(method, default=nil)
    respond_to? method ? send method : default
    end

    T.

    T.

Other Posts to Enjoy

Twitter Mentions