How to fix "extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)"
If you're on Ubuntu: sudo apt-get install ruby-dev On other platforms: Look for a package containing ruby...
Speed up RSpec by deferring garbage collection
Update: This trick probably isn't very useful anymore in Ruby 2.x. The Ruby GC has improved a lot...
Silencing Deprecation Warnings in Rspec
If you’re testing the behavior of deprecated code in your Ruby project, the warning messages littered throughout your spec...
Iterate over every n-th element of a Range in Ruby
If you want to iterate over a Range, but only look at every n-th element, use the step method...
Default block arguments for Ruby 1.8.7
When your block takes an argument that should have an default, only in Ruby 1.9 you can say: block = lambda...
Overriding unary operators in Ruby
This must be one of the coolest, yet quite unknown, technique in Ruby. For certain types of problems (e.g. when...
Word boundaries in MySQL regular expressions
In regular expressions you can use the zero-width pattern \b to match the beginning or end of a word...
The Ruby Infinite Hash
How to create an infinitely nestable hash that always defaults to a new hash if a key does not map...
Force net/http to verify SSL certificates
Ruby's net/http is setup to never verify SSL certificates by default. Most ruby libraries do the same. That means...
Capistrano cowboy deploys
Sometimes, you just need to shoot from the hip…or deploy your local changes without committing them. Put this snippet...
Check if two arrays contain the same elements in Ruby, RSpec or Test::Unit
RSpec 1, RSpec 2 To test whether two arrays have the same elements regardless of order, RSpec 1 and 2...
Encode or decode HTML entities
Use the htmlentities gem. Encoding works like this: require 'htmlentities' coder = HTMLEntities.new string = "<élan>" coder.encode(string) # => "<élan>"
Never use YAML.load with user input
You can get YAML.load to instantiate any Ruby object by embedding the desired class name into the YAML code. E.g...
Open a page in the default browser
Use the Launchy gem: Launchy.open('http://www.ruby-lang.org/')
Change the current directory without side effects in Ruby
To temporarily change the current working directory in Ruby, call Dir.chdir with a block. The previous working directory will be...
Ruby 2.0 Refinements in Practice
The first thing you need to understand is that the purpose of refinements in Ruby 2.0 is to make monkey...
MySQL: Select a default value for NULL fields
If you need to do calculations inside the database and can not use Ruby objects you may run into problems...
Install RubyMine under Ubuntu
This card explains how to install RubyMine for the first time. If you want to upgrade an existing RubyMine installation...
Installing Nokogiri
Because Nokogiri needs to be compiled and dynamically linked against both libxml2 and libxslt, it has gained a reputation for...
Hunt down that elusive debug message in Ruby
When you just went through a long debug-fest and infested your code with dozens of debug messages, it can...
Take care when joining and selecting on scopes
Occasionally some complex query must be processed on the database because building thousands of Ruby objects is impracticable.
Test a gem in multiple versions of Rails
Plugins (and gems) are typically tested using a complete sample rails application that lives in the spec folder of the...
Prevent Bundler from downloading the internet
As a user of Bundler you have spent significant time looking at this message: Fetching source index for http://rubygems.org...
Generate a Unicode nonbreaking space in Ruby
Regular spaces and non-breaking spaces are hard to distinguish for a human. Instead of using the HTML entity...