small medium large xlarge

Generic-user-small
11 Jun 2008, 00:18
joshua (1 post)

Given: def empty_cart session[:cart] = nil flash[:notice] = “Your cart is currently empty” redirect_to :action => :index end

I am curious about :notice (and :cart). Where do these variables come from? Dealing with :cart first, in add_to_cart, we have: @cart = find_cart // which returns session[:cart] ||= Cart.new

So, reverting to my C/C++ I would imagine thinking of Cart.new returning and address of the Cart object (i.e. new Cart()). Then session[:cart] would be an index into a dictionary, but what is :cart? It hasn’t been assigned… I am confused here.

As for :notice, is that an invisible parameter? Global? Same questions on assignment.

Sorry for my ignorance of the language. Feel free to point me to a doc that explains this (i will continue looking on my own as well).

Samr_small_pragsmall
12 Jun 2008, 00:59
Sam Ruby (634 posts)

Appendix a2 covers this briefly, but if you are familiar with C/C++, there are no variable declarations in Ruby. Instead there are a few conventions. Variable names that start with a capital letter are const, and variable names that start with a colon are implicitly part of an open ended enum declaration.

You must be logged in to comment