Discussions of Rails coding style always come back to the frequent use of symbol objects (such as :editions) as method arguments and/or hash keys in Rails applications.
In many cases, symbols serves usually with longer argument lists:
<%= link_to "A hyperlink in a view template",:controller => "main",:action => "welcome" %>
In this example, each symbol is associated with a value: the symbol :controller with the string “main”, the symbol :action with the string “welcome”. (The two symbols are hash keys, and the two strings are the corresponding hash values. The entire hash is the second argument to the method; the first argument is the first string: “A hyperlink in a view template”.) This syntax is standard Ruby.
It’s worth noting that the tendency of Rails developers to adhere to certain stylistic conventions becomes more important as the code gets more complex.
Saturday, March 10, 2007
The frequent use of symbol objects as method arguments or hash keys
Labels: Rails, Rails Convention, Ruby Syntax, Symbol
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment