1 2 3 4 5 6 7
def is_pos_activation? if session[:pos_activation] block_given? ? yield : true else false end end
Refactorings
No refactoring yet !
Adam
July 22, 2010, July 22, 2010 00:06, permalink
1 2 3 4
def is_pos_activation? return yield if block_given? session[:pos_activation] end
Martin Plöger
July 22, 2010, July 22, 2010 07:32, permalink
@Adam: you call the block even if session[:pos_activation] evaluates to false unlike the original code. (Don't know if it matters or has side-effects)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
def is_pos_activation? return yield if block_given? && session[:pos_activation] session[:pos_activation] end #OR def is_pos_activation? (block_given? && session[:pos_activation]) ? yield : session[:pos_activation] end #OR def is_pos_activation? session[:pos_activation] && (block_given? ? yield : true) end
bob
July 22, 2010, July 22, 2010 16:15, permalink
1 2 3
def is_pos_activation? session[:pos_activation] && (!block_given? || yield) end
i like this code, but exist another way more 'rubyst' to write it?