Notes posted by suzuki
RSS feed
0 thanks
Fetch with default value
You can specify default value as a fail-back if a hash doesn’t have a given key.
{a: false}.fetch(:b, true) => true {a: false}.fetch(:a, true) => false
It is useful especially in the case where you want to set default value for a method.
def initialize(args) @foo = args.fetch(:foo, 1) @bar = args.fetch(:bar, 2) # This can take over the following way. # `@bar = args[:bar] || 2` # => @bar is overwritten if caller specifies nil for :bar! end

0 thanks

0 thanks
#performed? is an option when getting ActionController::DoubleRenderError
You can avoid `ActionController::DoubleRenderError (Can only render or redirect once per action)` with `#performed?`
For example
def index redirect_to not_found_path unless authenticated? render :action => 'update' unless performed? end