duncanbeevers
has_finder with behavior
~4 years ago by duncanbeevers on dweebd.
Nick Kallen noted that the behavior of has_many_with_args can be accomplished using has_finder. Too true! Imagine a system in which Users send Whispers...
Resizing and cropping images to fixed dimensions
~4 years ago by duncanbeevers on dweebd.
The subject of cropping and resizing images comes up fairly often in the Rails community, with a number of tools out there to automate these manipulations...
Array delete_first
~4 years ago by duncanbeevers on dweebd.
Delete and return the first instance of a given object from an array. class Array def delete_first(to_delete) self.each_with_index do |item, index...
bool_attr_accessor for convenient question marks
~4 years ago by duncanbeevers on dweebd.
Ruby’s attr_accessor is incredibly handy for wiring up your class’s banal getters and setters. If you’re wiring up some simple booleans this way...
named_scope and subclasses
almost 4 years ago by duncanbeevers on dweebd.
Nick Kallen’s named_scope allows you to create readable, powerful class-specific finder scopes. One thing that might bite new users is how it operates...
Setting up an encrypted store in Mac OS
almost 4 years ago by duncanbeevers on dweebd.
Some of my co-workers like to use Notational Velocity to store sensitive information. Though a fine application, I’m partial to my existing tools and...
Poll until a property becomes available
almost 4 years ago by duncanbeevers on dweebd.
When dealing with ActionScript’s ExternalInterface.addCallback the method to be exposed might not be immediately available. whenAvailable polls until...
Shorthand named scopes
almost 4 years ago by duncanbeevers on dweebd.
In the old days, we did this: User.find(:all, :conditions => { :subscribed => true }, :order => 'created_at DESC' ) And then this: User.find_all_by_subscribed...
Steppin’
over 3 years ago by duncanbeevers on dweebd.
module Foo def shared 'Foo shared' end  def foobar shared end end  module Moo def shared 'Moo shared' end  def moobar end...
TestCase setup and teardown hooks
over 3 years ago by duncanbeevers on dweebd.
A little-known and very useful feature Rails brings to the table in terms of testing is a pair of callback hooks for Test::Unit::TestCase setup and teardown...
