Saturday, June 6, 2009

irb + rails quickly

irb -r "/config/environment"

Tuesday, June 2, 2009

Install ruby 1.9.1

To install ruby1.9 without impacting your current ruby installation, try the following steps:
1. Compile and Install readline (latest is 6.0) if you don't have already.

curl -O
tar xzvf readline-6.0.tar.gz
cd readline-6.0
./configure --prefix=/usr/local
make & sudo make install

2. Compile and install ruby 1.9.1.

curl -o ruby-1.9.1-p129.tar.gz
tar xzvf ruby-1.9.1-p129.tar.gz
cd ruby-1.9.1-p129
./configure --program-suffix=19 --enable-shared --with-readline-dir=/usr/local
make & sudo make install

3. Test

> irb19
> ruby19 -v
> gem19 -v

Wednesday, February 18, 2009

Rails plugins for authentication, metrics

I found the authlogic plugin a great help for simplifying authentication for a rails app. I have also used restful_authentication before, but I liked the idea of having a plugin for the authentication rather than generating an User or likes.

Metric_fu as a plugin is very helpful in understanging an existing project or improving the code quality. I like the metrics from Flog, Saikuro and Source Control Churn.

Other Links:
What's a Good Flog Score?
Saikuro - a cyclomatic complexity analyzer.

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