How to fix "extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)"

Posted Over 13 years ago by Thomas Eisenbarth.

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

Posted Over 13 years ago by Henning Koch.

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

Posted Over 13 years ago by Lexy.
justinfrench.com

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

Posted Over 13 years ago by Henning Koch.

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

Posted Over 13 years ago by Henning Koch.

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

Posted Over 13 years ago by Lexy.
timeless.judofyr.net

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

Posted Over 13 years ago by Henning Koch.

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

The Ruby Infinite Hash

Posted Over 13 years ago by Lexy.
opensoul.org

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

Posted Over 13 years ago by Lexy.
github.com

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

Capistrano cowboy deploys

Posted Over 13 years ago by Lexy.
opensoul.org

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

Posted Over 13 years ago by Henning Koch.

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

Posted Over 13 years ago by Henning Koch.

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

Never use YAML.load with user input

Posted Over 13 years ago by Henning Koch.

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

Posted Over 13 years ago by Henning Koch.

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

Change the current directory without side effects in Ruby

Posted Over 13 years ago by Henning Koch.
apidock.com

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

Posted Over 13 years ago by Lexy.
yehudakatz.com

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

Posted Over 13 years ago by Arne Hartherz.

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

Install RubyMine under Ubuntu

Posted Over 13 years ago by Henning Koch.

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

Installing Nokogiri

Posted Over 13 years ago by Lexy.
nokogiri.org

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

Posted Over 13 years ago by Henning Koch.

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

Posted Over 13 years ago by Arne Hartherz.

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

Posted Over 13 years ago by Tobias Kraze.

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

Posted Over 13 years ago by Henning Koch.

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

Posted Over 13 years ago by Arne Hartherz.

Regular spaces and non-breaking spaces are hard to distinguish for a human. Instead of using the &nbsp; HTML entity...