I was trying to write a wrapper for number_to_currency to return currency in pounds. I used a helper class to do this. def number_to_pounds(amt) number_to_currency(amt, :unit => "£") end This works fine, but I am trying to understand why I can''t use a symbol to pass the values. I thought symbols were like pointers. (you now know I am a newbie). def number_to_pounds(:amt) number_to_currency(:amt, :unit => "£") end Note - amt is not the name of the variable my view works on, it is price, so I tried the symbol :price, it wouldn''t work either. I am googling to learn about the symbols. Any link for that would be really helpful. Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 16 Oct, 23:01, Arun Srini <arunro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was trying to write a wrapper for number_to_currency to return > currency in pounds. I used a helper class to do this. > > def number_to_pounds(amt) > number_to_currency(amt, :unit => "£") > end > > This works fine, but I am trying to understand why I can''t use a > symbol to pass the values. I thought symbols were like pointers. (you > now know I am a newbie). >A symbol is an interned string - :foo is a literal much like ''foo'', [] or 3: it clearly does not make sense to declare a function with the first argument being any sort of literal http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings has some good stuff about symbols Fred> def number_to_pounds(:amt) > number_to_currency(:amt, :unit => "£") > end > > Note - amt is not the name of the variable my view works on, it is > price, so I tried the symbol :price, it wouldn''t work either. I am > googling to learn about the symbols. Any link for that would be really > helpful. > > Thanks-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
thanks.. I did read a lot about the difference between symbols and strings. I have another question here regarding the internal workings of rails and how it uses symbols. I am following the pragmatic programmers book on rails developing the depot application. Here I declare a scaffold line_item with two integers to hold the relationship between the product and the cart. In the cart controller- I use the symbol '':line_items'', no where did I declare or even tell the universe there would be some symbol to denote a line_item. Is this how rails works? a default symbol for models that could be used to store the objects for that model to be used in controllers?? If someone could link me to a blog post explaining this rails character, I''ll be really happy. Thanks Arun On Oct 16, 6:22 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 16 Oct, 23:01, Arun Srini <arunro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I was trying to write a wrapper for number_to_currency to return > > currency in pounds. I used a helper class to do this. > > > def number_to_pounds(amt) > > number_to_currency(amt, :unit => "£") > > end > > > This works fine, but I am trying to understand why I can''t use a > > symbol to pass the values. I thought symbols were like pointers. (you > > now know I am a newbie). > > A symbol is an interned string - :foo is a literal much like ''foo'', [] > or 3: it clearly does not make sense to declare a function with the > first argument being any sort of literalhttp://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings > has some good stuff about symbols > > Fred > > > > > def number_to_pounds(:amt) > > number_to_currency(:amt, :unit => "£") > > end > > > Note - amt is not the name of the variable my view works on, it is > > price, so I tried the symbol :price, it wouldn''t work either. I am > > googling to learn about the symbols. Any link for that would be really > > helpful. > > > Thanks-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 17, 4:11 pm, Arun Srini <arunro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am following the pragmatic programmers book on rails developing the > depot application. Here I declare a scaffold line_item with two > integers to hold the relationship between the product and the cart. > In the cart controller- I use the symbol '':line_items'', no where did I > declare or even tell the universe there would be some symbol to denote > a line_item. Is this how rails works? a default symbol for models that > could be used to store the objects for that model to be used in > controllers?? If someone could link me to a blog post explaining this > rails character, I''ll be really happy. >This isn''t really about rails. :line_items is just a literal - you don''t have to declare it, just as you don''t have to declare the string "line_items": typing it is enough to bring it into existance. You might also want to read http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols Fred> Thanks > Arun > > On Oct 16, 6:22 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On 16 Oct, 23:01, Arun Srini <arunro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I was trying to write a wrapper for number_to_currency to return > > > currency in pounds. I used a helper class to do this. > > > > def number_to_pounds(amt) > > > number_to_currency(amt, :unit => "£") > > > end > > > > This works fine, but I am trying to understand why I can''t use a > > > symbol to pass the values. I thought symbols were like pointers. (you > > > now know I am a newbie). > > > A symbol is an interned string - :foo is a literal much like ''foo'', [] > > or 3: it clearly does not make sense to declare a function with the > > first argument being any sort of literalhttp://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings > > has some good stuff about symbols > > > Fred > > > > def number_to_pounds(:amt) > > > number_to_currency(:amt, :unit => "£") > > > end > > > > Note - amt is not the name of the variable my view works on, it is > > > price, so I tried the symbol :price, it wouldn''t work either. I am > > > googling to learn about the symbols. Any link for that would be really > > > helpful. > > > > Thanks-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.