Eagerness

svoop Mar 8, 2010

Check out this simple example:

"Hello Ruby friend".sub(/^(.)e/, 'X') # => "Xnd" "Hello Ruby friend".sub(/^(.?)e/, 'X') # => "Xllo Ruby friend"

The question mark turns the dotstar into non-eager mode which means it will halt on the first subsequent "e" rather than the last one. This comes in...

makedirs(path) to create file path

allen Mar 2, 2010 4 thanks

mkdir will only create a single directory on an existing path. If you want to create a full path, like the mkdir -p /full/path command, use the makedirs method.

1.8: File.makedirs(path) 1.9: FileUtils.makedirs(path)

default_scope on create

squil Feb 26, 2010 3 thanks

If you specify +:conditions+ in your +default_scope+ in form of a Hash, they will also be applied as default values for newly created objects. Example:

class Article
default_scope :conditions => {:published => true}
end

Article.new.published? # => true

However:

class Article...

Possible gotcha

szeryf Feb 25, 2010 2 thanks

This method returns a Pathname object which handles paths starting with a / as absolute (starting from the root of the filesystem). Compare:

>> Rails.root
=> #<Pathname:/some/path/to/project>
>> Rails.root + "file"
=> #<Pathname:/some/path/to/project/file>
>> Rails.root + "/file...