Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

http://installingcats.com

Showing 11 - 13 of 13 total

alias class methods in Ruby

module ActiveRecord

  class Base

    class << self
      alias old_establish_connection establish_connection
    end

    def self.establish_connection(arg)
      logger.debug("Establishing connection")
      self.old_establish_connection(arg)
    end
  end
end

Another approach might be to use super like this:
module ActiveRecord
  class Base
    def self.establish_connection(arg)
      logger.debug("Establishing connection")
      super arg
    end
  end
end 

debug print Hpricot xml object

// description of your code here

debug(@instance_var.pretty_inspect)

urlencode in Ruby

Use the CGI class to url encode stuff. Have to load the CGI class before using its methods though.

require 'cgi'
CGI.escape([your junk])
Showing 11 - 13 of 13 total