Note: Consider not doing this. Use form models or vanilla methods instead. The :conditions option for Rails associations cannot take...

Given those modules: module A def foo; end def bar; end end module B end When you want to call...

makandra dev

Given group size If you would like to split a Ruby array into pairs of two, you can use the...

opensoul.org

I love ETags, but there’s something that annoys me: most implementations revolve around pulling a record out of a...

If you're on Ubuntu: sudo apt-get install ruby-dev On other platforms: Look for a package containing ruby...

Update: This trick probably isn't very useful anymore in Ruby 2.x. The Ruby GC has improved a lot...

justinfrench.com

If you’re testing the behavior of deprecated code in your Ruby project, the warning messages littered throughout your spec...

If you want to iterate over a Range, but only look at every n-th element, use the step method...

When your block takes an argument that should have an default, only in Ruby 1.9 you can say: block = lambda...

timeless.judofyr.net

This must be one of the coolest, yet quite unknown, technique in Ruby. For certain types of problems (e.g. when...

In regular expressions you can use the zero-width pattern \b to match the beginning or end of a word...

opensoul.org

How to create an infinitely nestable hash that always defaults to a new hash if a key does not map...

github.com

Ruby's net/http is setup to never verify SSL certificates by default. Most ruby libraries do the same. That means...

opensoul.org

Sometimes, you just need to shoot from the hip…or deploy your local changes without committing them. Put this snippet...

If you want to find out whether a Class object is directly inheriting from another class, use superclass: ActiveRecord::RecordNotFound.super...

RSpec 1, RSpec 2 To test whether two arrays have the same elements regardless of order, RSpec 1 and 2...

Use the htmlentities gem. Encoding works like this: require 'htmlentities' coder = HTMLEntities.new string = "<élan>" coder.encode(string) # => "&lt;élan&gt;"

You can get YAML.load to instantiate any Ruby object by embedding the desired class name into the YAML code. E.g...

Use the Launchy gem: Launchy.open('http://www.ruby-lang.org/')

apidock.com

To temporarily change the current working directory in Ruby, call Dir.chdir with a block. The previous working directory will be...

yehudakatz.com

The first thing you need to understand is that the purpose of refinements in Ruby 2.0 is to make monkey...

If you need to do calculations inside the database and can not use Ruby objects you may run into problems...

This card explains how to install RubyMine for the first time. If you want to upgrade an existing RubyMine installation...

nokogiri.org

Because Nokogiri needs to be compiled and dynamically linked against both libxml2 and libxslt, it has gained a reputation for...