Friday, December 5, 2008

Ruby Metaprogramming

Define a metaclass

class Object
def metaclass; class << self; self; end; end

Rails style of extending class and instance methods(also available as a textmate snippet mod ->)

module ModuleName
module ClassMethods

module InstanceMethods

def self.included(receiver)
receiver.extend ClassMethods
receiver.send :include, InstanceMethods

Seeing Metaclasses Clearly
Metaprogramming by Dave Thomas
Dynamically Created Methods In Ruby
Ruby Metaprogramming techniques
Eval options in ruby

Monday, November 24, 2008

Location of ruby libraries

To find out the location of the ruby library modules, use command

ruby -e 'puts $:'

To find out the location of gem
gem which GEM-NAME

Sunday, November 23, 2008

Upgrading to Rails 2.2.x for Leopard

I am trying to upgrade one of my applications from the frozen rails version 2.1.1 to 2.2.2.
The steps I used:

rake rails:freeze:gems

As the mysql driver has been excluded from rails now, I thought the gem installation would be simple, but I had to find out the exact options needed and the path of the respective locations needed by those options.
As I had installed mysql with the OS X package installer, I had to use:

sudo gem install mysql -- --with-mysql-include=/usr/local/mysql/ --with-mysql-lib=/usr/local/mysql/lib --with-mysql-config=/usr/local/mysql/bin/mysql_config

I got error LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded:
to fix that:

sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib /usr/local/mysql/lib/libmysqlclient.15.dylib /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

Then I had to fix the errors for rspec by

ruby script/plugin install git://
ruby script/plugin install git://
ruby script/generate rspec

For mysql installation done with port

sudo gem install mysql -- --with-mysql-include=/opt/local/include/mysql5/mysql/ --with-mysql-lib=/opt/local/lib/mysql5/mysql/ --with-mysql-config=/opt/local/bin/mysql_config5

Friday, May 9, 2008

RSpec on textmate

While working with Sreekanth V, we came across a peculiar problem with Textmate. For the *_spec.rb, the bundle need to be changed to the RSpec on textmate so that that particular test can be run as a spec otherwise it would throw the environment error. So we changed the *_spec.rb files to *.spec and associated the RSpec bundle to fileType *.spec. To make the rake spec task to work we changed the rspec.rake file to include 'spec/**/*.spec' in all the file lists e.g.

t.spec_files = FileList['spec/**/*_spec.rb', 'spec/**/*.spec']

Friday, May 2, 2008

IntelliJ Editor pane looks like Textmate

Insipred by the VibrantInk theme used in Textmate, I have created a similar colors and fonts scheme for IntelliJ. I am using monaco font for this scheme.

Saturday, April 19, 2008

Semantic Web

Semantic web is a concept to design, collaborate, interpret and publish information on the web.
More details @
A nice presentation on this topic at google tech talks: