def vs. define_method

Posted About 11 years ago by Dominik Schöler.

Ever wondered about the difference between def and define_method? Turns out there are three implicit contexts in Ruby. def...

How to make Rational#to_s return strings without denominator 1 again

Posted About 11 years ago by Arne Hartherz.

The way Rational#to_s works on Ruby has changed from Ruby 1.9 on. Here is how to get the...

Protected and Private Methods in Ruby

Posted About 11 years ago by Dominik Schöler.
tenderlovemaking.com

In Ruby, the meaning of protected and private is different from other languages like Java. (They don't hide methods...

Ruby: Finding where a method is defined

Posted About 11 years ago by Dominik Schöler.
stackoverflow.com

Dead simple: Get the method object and ask for its owner: "foo".method(:upcase) => # "foo".method(:upcase).owner => String

Fix „rvm no such file to load -- openssl“ or "rvm no such file to load -- zlib"

Posted About 11 years ago.

For example if you use rvm and get this message: ERROR: Loading command: install (LoadError) no such file to load...

Ruby 1.9 or Ruby 2.0 do not allow using shortcut blocks for private methods

Posted About 11 years ago by Arne Hartherz.

Consider this class: class Foo private def test puts "Hello" end end While you can say create a block to...

Different behavior for BigDecimal#floor in Ruby 1.8 and Ruby 1.9

Posted About 11 years ago by Ulrich Berkmueller.

Ruby 1.8 (supplied by Rails' ActiveSupport) >> BigDecimal.new("0.1").floor.class => BigDecimal Ruby 1.9 (supplied by Ruby 1.9 itself) >> BigDecimal.new("0.1").floor.class...

How to: Ruby heredoc without interpolation

Posted About 11 years ago by Arne Hartherz.
jeff.dallien.net

When you use heredoc, string interpolation is enabled by default: x = "Universe" <<-MESSAGE Hello #{x} MESSAGE # => "Hello Universe"

Capistrano: Bundler stalls and asks for "Username"

Posted About 11 years ago by Thomas Eisenbarth.

Given you use Capistrano together with bundler to automatically install your gems when deploying. I recently had the problem that...

instance_eval behaves different in Ruby 1.8 and Ruby 1.9, use instance_exec instead

Posted About 11 years ago by Henning Koch.

In Ruby 1.9, instance_eval calls the block the with receiver as the first argument: In Ruby 1.8, receiver.instance_eval...

MongoMapper for Rails 2 on Ruby 1.9

Posted About 11 years ago by Arne Hartherz.
github.com

MongoMapper is a MongoDB adapter for Ruby. We've forked it so it works for Rails 2.3.x applications running...

"Module.const_defined?" behaves differently in Ruby 1.9 and Ruby 1.8

Posted About 11 years ago by Arne Hartherz.
apidock.com

Ruby 1.9 changed the default behavior of Module.const_defined? from what it was in Ruby 1.8 – this can be especially...

Fix error "invalid byte sequence in US-ASCII" in .js.erb files

Posted About 11 years ago by Henning Koch.

This error can happen in Ruby 1.9. To fix it, add the following line to the top of your .js.erb...

How to silence UTF-8 warnings on Rails 2.3 with Ruby 1.9

Posted About 11 years ago by Arne Hartherz.
gist.github.com

Rails 2.3.16+ on Ruby 1.9 causes warnings like this: .../gems/activesupport-2.3.17/lib/active_support/core_ext/string/output_safety.rb:22: warning: regexp match /.../n against to UTF-8 string...

A regular expression that will never match

Posted About 11 years ago by Arne Hartherz.
perl.plover.com

So you have a method returning a regular expression but one case that should not yield a matching Regexp object...

rsl/stringex · GitHub

Posted About 11 years ago by Arne Hartherz.
github.com

Stringex is a gem that offers some extensions to Ruby's String class. Ruby 1.9 compatible, and knows its way...

lang/unicode_utils · GitHub

Posted About 11 years ago by Arne Hartherz.
github.com

UnicodeUtils implements Unicode algorithms for case conversion, normalization, text segmentation and more in pure Ruby code.

How to fix: RVM does not offer recent Ruby versions

Posted About 11 years ago by Arne Hartherz.

RVM needs to be updated regularly to know of Ruby versions released since installation (or last update).

Edge Rider: Power tools for ActiveRecord scopes

Posted About 11 years ago by Henning Koch.

In our continued quest to extract proven code snippets from makandropedia into tested and upgradable gems, we have released Edge...

The many gotchas of Ruby class variables

Posted About 11 years ago by Henning Koch.

TLDR: Ruby class variables (@@foo) are dangerous in many ways. You should avoid them at all cost. See bottom of...

Prevent double clicks on link_to_remote (simple case)

Posted About 11 years ago.

This works well in the simplified case, when your link disappears after it was clicked. Let link_to_remote behave...

Regex: Be careful when trying to match the start and/or end of a text

Posted About 11 years ago by Thomas Eisenbarth.

Ruby has two different ways to match the start and the end of a text: ^ (Start of line) and $ (End...

What The Rails Security Issue Means For Your Startup

Posted About 11 years ago by Henning Koch.
kalzumeus.com

January has been a very bad month for Ruby on Rails developers, with two high-severity security bugs permitting remote...

How to update a single gem conservatively

Posted About 11 years ago by Henning Koch.

Calling bundle update GEMNAME will update a lot more gems than you think. E.g. when you do this...