How to update RubyGems binary for all installed rubies

Posted Over 8 years ago by Arne Hartherz.

To update your Rubygems to the latest available version, type the following: gem update --system Note that you have a...

Matching unicode characters in a Ruby (1.9+) regexp

Posted Over 8 years ago by Tobias Kraze.

On Ruby 1.9+, standard ruby character classes like \w, \d will only match 7-Bit ASCII characters: "foo" =~ /\w+/ # matches...

List RubyGems binary version for all installed Ruby versions

Posted Over 8 years ago by Kim Klotz.

To check which rubygems versions your different rbenv rubys are using, you can use this small bash script:

List of Helpful RubyMine Shortcuts

Posted Over 8 years ago by Dominik Schöler.

CTRL + SHIFT + ALT + N : Search for any symbol in your application, like CSS classes, Ruby classes, methods, helpers etc...

The Complete Guide to Rails Caching

Posted Almost 9 years ago by Henning Koch.
nateberkopec.com

Very detailed guide to caching Ruby on Rails. Goes well with the official Rails guide on caching.

Savon: Use complex SOAP types as arguments

Posted Almost 9 years ago by Henning Koch.

If a SOAP API expects you to call a remote method with arguments of complex types, Savon lets you manually...

Understanding Ruby Singleton Classes

Posted Almost 9 years ago by Andreas Robecke.
devalot.com

Good article about ruby singleton classes.

Testing regular expressions visually

Posted Almost 9 years ago by Thomas Klemm.

Developing complex regular expressions quickly blows my mind. Here are some online regex editors that help you by highlighting matching...

Upgrading from Capistrano 2 to 3

Posted Almost 9 years ago by Dominik Schöler.
semaphoreci.com

Capistrano 3 is a major rework of the framework and requires several adjustments to your deploy configuration files. The biggest...

ActiveRecord: How to use ActiveRecord standalone within a Ruby script

Posted Almost 9 years ago by Thomas Klemm.
gist.github.com

Re-creating a complex ActiveRecord scenario quickly without setting up a full-blown Rails app can come in handy e.g...

RubyMine: Scratch files

Posted Almost 9 years ago by Arne Hartherz.
plugins.jetbrains.com

There are times when you have a chunk of text that you want to do something with, e.g. replace something...

Ruby bug: Symbolized Strings Break Keyword Arguments in Ruby 2.2

Posted Almost 9 years ago by Dominik Schöler.
bugs.ruby-lang.org

TL;DR Under certain circumstances, dynamically defined symbols may break keyword arguments in Ruby 2.2. This was fixed in Ruby...

What Ruby’s ||= (Double Pipe / Or Equals) Really Does

Posted Almost 9 years ago.
rubyinside.com

It is a common misunderstanding that all [op]=-operators work the same way, but actually they don't. ||= and &&=

Using mime types with send_file

Posted Almost 9 years ago.
iana.org

When using send_file (for example for attachments of any kind), make sure your application knows the correct mime types...

Unfreeze a frozen ActiveRecord

Posted Almost 9 years ago by Henning Koch.

You can freeze any Ruby object to prevent further modification. If you freeze an ActiveRecord and try to set an...

Ruby: How to grow or shrink an array to a given size

Posted About 9 years ago by Arne Hartherz.

If you want to grow a Ruby Array, you might find out about #fill but it is not really what...

Rubymine: Code folding

Posted About 9 years ago by Dominik Schöler.

Code folding is a very useful feature to me. It gives me a quick overview over a file and keeps...

Thread-safe collections in Ruby

Posted About 9 years ago by Henning Koch.

When using threads, you must make your code thread-safe. This can be done by either locking (mutexes) all data...

Rails has a built-in slug generator

Posted About 9 years ago by Henning Koch.

Today I learned that Ruby on Rails has shipped with a built-in slug generator since Rails 2.2:

skorks/nesty

Posted About 9 years ago by Henning Koch.
github.com

Nested exceptions for Ruby: When you rescue an error and then re-raise your own, you don't have to...

Differences between transactions and locking

Posted About 9 years ago by Henning Koch.

Web applications can be used by multiple users at the same time. A typical application server like Passenger has multiple...

Custom loggers in Ruby and Rails

Posted About 9 years ago by Henning Koch.

If you need to log to a file you can use Ruby's Logger class: require 'logger'

Linux: Kill a process matching a partial name

Posted About 9 years ago by Henning Koch.

This is useful to kill processes like ruby my-script.rb: pkill -f my-script.rb With great power comes great responsibility.

Ruby: Removing leading whitespace from HEREDOCs

Posted About 9 years ago by Henning Koch.

If you're on Ruby 2.3+ there's a <<~ operator to automatically unindent HEREDOCs: str = <<~MESSAGE Hello Universe!