alphagov/pethau — pull request #1 by craigw (2011-10-24 15:30:05+00:00)
Title: Supplying default values for fields and creating private fields

Hacking on a little project, found these behaviours useful. I'll merge them in tomorrow if no one objects?

class Breakfast
initialize_with :liquid, :food

default_value_of :food, "Bacon"
default_value_of :liquid do
logger.info "Official Coffee Times Commence"
kettle = StoveTopEspressoMachine.check_out
# [... make coffee with the kettle ...]
kettle.pour
kettle.clean
end

private_attr_accessor :logger
default_value_of :logger do MissingLogger.instance end
end