Floyd’s Thoughts…

Because Everything is Interesting!!!

Archive for August 13th, 2008

Something I didn’t know Yesterday #2

without comments

Rails (or should i say ActiveSupport) adds a blank? instance method to object that encapsulates the nil? || empty? check that I find myself doing all the time.

A quick review of the source show that the empty? method is added to the following:

  # An object is blank if it's nil, empty, or a whitespace string.
  # For example, "", "   ", nil, [], and {} are blank.
  #
  # This simplifies
  #   if !address.nil? && !address.empty?
  # to
  #   if !address.blank?

The full source is actually very simple (I Love Ruby)

class Object
 
  def blank?
    if respond_to?(:empty?) && respond_to?(:strip)
      empty? or strip.empty?
    elsif respond_to?(:empty?)
      empty?
    else
      !self
    end
  end
end
 
class NilClass #:nodoc:
  def blank?
    true
  end
end
 
class FalseClass #:nodoc:
  def blank?
    true
  end
end
 
class TrueClass #:nodoc:
  def blank?
    false
  end
end
 
class Array #:nodoc:
  alias_method :blank?, :empty?
end
 
class Hash #:nodoc:
  alias_method :blank?, :empty?
end
 
class String #:nodoc:
  def blank?
    empty? || strip.empty?
  end
end
 
class Numeric #:nodoc:
  def blank?
    false
  end
end

Written by Floyd Price

August 13th, 2008 at 8:46 pm

Installing Ruby Enterprise Edition on CentOS 5.2

with 2 comments

Installing Ruby 1.8.6 on CentOS is not as easy as you would hope. The YUM repositories do not have anywhere near the latest version of ruby so you are forced into installing from source, which means locating and installing many dependancies before building ruby itself.

I have found myself building ruby several times on a new CentOS box after realizing that i had missed a dependancy that was required to use rails or some other ruby component.

I was going to write up a step by step guide to installing Ruby 1.8.6, Rails, MySql, etc… on CentOS 5.2 (and i may still do this) however i have found that the guys who wrote Phusion Passenger have also build a version of Ruby that as well as having a lower memory footprint has a convenient installer that takes the pain out of building from source.

Here are my steps for installing Ruby Enterprise Edition on CentOS 5.2

* 1. ssh into CentOS using your favorite ssh client.
* 2. cd /usr/local/src
(this is where I downloaded the source to you can do this anywhere i guess)
* 3. sudo wget http://rubyforge.org/frs/download.php/41040/ruby-enterprise-1.8.6-20080810.tar.gz
(this is the latest version at the time of writing this post)
* 4. tar xzvf ruby-enterprise-1.8.6-20080810.tar.gz
* 5. sudo ./bin/ruby-enterprise-1.8.6-20080810/installer

The last step starts the convenient installer process that will build everything you need from sources.

I found that first time the script ran i didn’t have MySql or PostgreSQL development header files so i installed them using

* sudo yum install postgresql-devel.i386
* sudo um install mysql-devel.i386

After running the install script again it completed with no errors (you could have just ran the gem install again rather than installing the whole of ruby…)

The great thing about this installer is that it isolates the installation and does not touch any system files so it will not screw up any of your existing ruby installs.

We have been using Ruby Enterprise Edition on one of our projects for a few weeks now and i have to say that it works really well, and it also includes the recent security patches for ruby – sweet!

Oh don’t let the name put you off Ruby Enterprise Edition is actually Open Source – Yay ;-)

Written by Floyd Price

August 13th, 2008 at 8:04 pm

Posted in CentOS,Rails,Ruby

Daily Dose #2

without comments

Spent the best part of the day estimating development effort for an upcoming project… Yarn.

CMS Rails Kit
Ben Curtis has released a new CMS Rails Kit.

The Ruby Hoedown in 10 minutes
The guys from Rails Envy give a quick review of the Ruby Hoedown.

Ruby Visual Identity Team
Want to show the world that you love Ruby? Get a high quality Ruby image for your website.

ar-extensions 0.8.0 released!
Some handy extensions to Active Record that now work with Rails 2.1

Written by Floyd Price

August 13th, 2008 at 1:22 pm

Get Adobe Flash playerPlugin by wpburn.com wordpress themes