Argument Ordering

tadman Apr 23, 2009 6 thanks

Be aware that the order of arguments for this method is the opposite of File.join:

File.expand_path('foo', '/bar')   # => "/bar/foo"
File.join('foo', '/bar')          # => "foo/bar"

Customize Formatting with a Subclass

tadman Apr 23, 2009 1 thank

Instead of passing in a formatter block, you can always create a subclass that defines the format:

require 'logger'

class MyLogger < Logger
def format_message(severity, datetime, progname, msg)
  "[%s %s] %s\

" % [ severity, datetime.strtftime("%H:%M"), msg ] end end

This...

Rails and Ruby 1.8.7 Extensions

tadman Apr 23, 2009 2 thanks

Note that the use of Symbol#to_proc requires either Rails or Ruby 1.8.7. Prior versions will show:

['a', 'b', 'c'].collect(&:capitalize)
 #  => TypeError: wrong argument type Symbol (expected Proc)

Using strings as association names

netmaniac Apr 23, 2009 1 thank

Beware, that using strings as association names, when giving Hash to :include will render errors:

The error occurred while evaluating nil.name

So, :include => ['assoc1', 'assoc2' ] will work, and :include => [ {'assoc1' => 'assoc3'}, 'assoc2'] won't. Use symbols:

==== Proper form

:include => [...