Ruby DSL Trick with the Hash
Today I had to rig up a method for defining symlinks in Capistrano. I never really liked how the ln command worked to begin with; I think of symlinks in terms of:
Alias A targets File B
To make this easier I wrote up this method:
def link(link)
source, target = link.keys.first, link.values.first
run "ln -nfs #{target} #{source}"
end
Which reads as:
link "alias_a" => "file_b"
I love finding these little ways that make my code more readable.
