Jesús Gabriel y Galán
12/23/2008 5:05:00 PM
On Tue, Dec 23, 2008 at 5:51 PM, Patrick Doyle <wpdster@gmail.com> wrote:
> Is there a cleaner, more Rubyesque way to do this?
>
> # Return a hash of the navigation parameters
> def nav_params
> params = {}
>
> params[:prefix] = @prefix if @prefix
> params[:category_id] = @category_id if @category_id
> params[:page] = @page if @page
>
> params
> end
>
> I want to load a parameters hash with the contents of some instance
> variables, but only if they are defined.
>
irb(main):005:0> {:prefix => @prefix, :category_id => @category, :page
=> @page}.reject {|k,v| v.nil?}
=> {:prefix=>"asdasdf", :category_id=>"cat"}
Jesus.