8 More Useful Ruby Code Snippets
Simple "Send Email from Ruby" method - Using Net::SMTP to talk to the local SMTP daemon directly to send mail. Not elegant, but a useful quick hack.
Helper to Display Rails Flashes - A helper method that formalizes and simplifies the displaying of certain flash variables in Rails views.
Rails and Vim - A script to open an entire Rails project in Vim (searches through for models, controllers, etc).
Using Ruby hashes as keyword arguments, with easy defaults - Make your life (and methods!) simpler by merging in a set of default options with the supplied ones.
Ruby daemon library - A useful Daemon module to simplify the creation of daemons in Ruby (the daemons gem may be better for this in the long run though).
Wrap Text with a Regular Expression - Wraps text to a specified column width using a single gsub.
Test Driven LDAP with Ruby - Testing the LDAP client library for Ruby (and your LDAP server!)
Ordinals for all Numeric Types - Extending Ruby's numeric types to suffix "st", "rd", "th", etc.
August 4, 2006 at 10:49 pm
I'm the author of the 4th snippet (ruby hashes as keyword arguments) - it turns out that Rails has this functionality built in in the form of the reverse_merge function, making my snippet pretty redundant if you are using Rails (though I do prefer the name with_defaults.
More discussion on this and alternatives can be found on my blog:
http://www.lukeredpath.co.uk/index.php/2006/07/27/using-ruby-hashes-as-keyword-arguments-with-easy-defaults/