Hello, I am a pretty new rails (and ruby) programmer, and learning the art and craft of rails programming. One thing I noticed about rails programming is that unlike perl there is usually one and only one cute and sweet way of doing a thing. Let me give 2 examples, 1. I want to check if a variable is null and assign it a value if it''s null. In other languages I would write an if clause to do this, but in rails the sweet way would be to use the ||= operator. 2. I want to render a table in a rails view. Normal way would be to write a loop, but the rails way is to use partials and pass the collection. I discovered these 2 techniques recently, and it got me to think these 2 are not the only such idioms and the beauty of ruby allows lots of such nifty techniques. But even after some googling around I am not aware of any site where these are collected and act as resources for programmers picking up ruby and rails. But I am sure there and such sites and more such nice idioms in rails and ruby, but where are they? :) Also what are your favorite idioms, that you would like to share? with regards, raj --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rajkumar S wrote:> Hello, > > I am a pretty new rails (and ruby) programmer, and learning the art > and craft of rails programming. One thing I noticed about rails > programming is that unlike perl there is usually one and only one cute > and sweet way of doing a thing. Let me give 2 examples, > > 1. I want to check if a variable is null and assign it a value if it''s > null. In other languages I would write an if clause to do this, but in > rails the sweet way would be to use the ||= operator. > > 2. I want to render a table in a rails view. Normal way would be to > write a loop, but the rails way is to use partials and pass the > collection. > > I discovered these 2 techniques recently, and it got me to think these > 2 are not the only such idioms and the beauty of ruby allows lots of > such nifty techniques. But even after some googling around I am not > aware of any site where these are collected and act as resources for > programmers picking up ruby and rails. But I am sure there and such > sites and more such nice idioms in rails and ruby, but where are they? > :) > > Also what are your favorite idioms, that you would like to share? > > with regards, > > raj > > > > >Check out: http://errtheblog.com/post/44 for lots of cool stuff (and subscribe to his blog -- it''s a goldmine) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/19/06, Chris T <ctmailinglists-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> http://errtheblog.com/post/44 > for lots of cool stuff (and subscribe to his blog -- it''s a goldmine)Very true. Thanks for the link. raj --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ryan.raaum-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-19 17:52 UTC
Re: Rails idioms?
On Dec 18, 12:55 pm, "Rajkumar S" <rajkum...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I am a pretty new rails (and ruby) programmer, and learning the art > and craft of rails programming. One thing I noticed about rails > programming is that unlike perl there is usually one and only one cute > and sweet way of doing a thing. Let me give 2 examples, > > 1. I want to check if a variable is null and assign it a value if it''s > null. In other languages I would write an if clause to do this, but in > rails the sweet way would be to use the ||= operator. > > 2. I want to render a table in a rails view. Normal way would be to > write a loop, but the rails way is to use partials and pass the > collection. > > I discovered these 2 techniques recently, and it got me to think these > 2 are not the only such idioms and the beauty of ruby allows lots of > such nifty techniques. But even after some googling around I am not > aware of any site where these are collected and act as resources for > programmers picking up ruby and rails. But I am sure there and such > sites and more such nice idioms in rails and ruby, but where are they? > :) > > Also what are your favorite idioms, that you would like to share?This RubyGarden page is a good reference: http://wiki.rubygarden.org/Ruby/page/show/RubyIdioms Best, -r> > with regards, > > raj-- Ryan Raaum http://raaum.org http://rails.raaum.org -- Rails docs http://locomotive.raaum.org -- Self contained Rails for Mac OS X --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---