Newbie : assign a value to a variable

On Aug 28, 2006, at 10:15 AM, Luc H. wrote:

You can also do:
per_page = @params.fetch(:per_page, 20)

Thanks for that. I’ve been oblivious to the default and block
options for fetch!

Gary W.

then per_page
per_page = nil if per_page <= 0 # validity check
per_page ||= 20 # default

Choose what you like best.

or get them all at once:

per_page = @params.fetch(:per_page, 0).nonzero? || 20

cheers

Simon