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...
Given group size If you would like to split a Ruby array into pairs of two, you can use the...
When defining a trait using the Modularity gem, you must take extra steps to define constants to avoid caveats (like...
In case https://www.rubydoc.info/ is to slow or offline, you can also read a gem documentation offline. Start a server...
I love ETags, but there’s something that annoys me: most implementations revolve around pulling a record out of a...
Are you adding a "Then show me the page" and re-run Cucumber whenever there is a failing scenario? Don...
If you're on Ubuntu: sudo apt-get install ruby-dev On other platforms: Look for a package containing ruby...
Call geordi clean from a project root to remove unused and unnecessary files inside it. This script is part of...
Update: This trick probably isn't very useful anymore in Ruby 2.x. The Ruby GC has improved a lot...
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...
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...
You can usually just use the eq matched to compare two numbers: expect(deal.total).to eq(120)
How to create an infinitely nestable hash that always defaults to a new hash if a key does not map...
Ruby's net/http is setup to never verify SSL certificates by default. Most ruby libraries do the same. That means...
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) # => "<élan>"
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/')