Rails #clasifica salida extraña

using rails 3.0.1 and ruby 1.9.2-p0

in the rails console I'm seeing the following:

ruby-1.9.2-p0 > "login_controller".classify
 => "LoginController"

ruby-1.9.2-p0 > {:controller=>"login", :action=>"show"}[:controller]+"_controller".classify
 => "login_controller" 

ruby-1.9.2-p0 > "login_controller" == {:controller=>"login", :action=>"show"}[:controller]+"_controller"
 => true 

¿Por qué es classify returning 'login_controller' for the one, and 'LoginController" for the other, when ruby says both strings are equal?

preguntado el 08 de enero de 11 a las 20:01

2 Respuestas

Your order of operations isn't right. In the second example, the implicit brackets are going like this:

{:controller=>"login", :action=>"show"}[:controller] + ("_controller".classify)

desde . se une antes +. To fix it, you can do this:

({:controller=>"login", :action=>"show"}[:controller] + "_controller").classify

ie, include the brackets yourself.

Respondido el 09 de enero de 11 a las 00:01

Never fails,

It's operator precedence. I need to do:

({:controller=>"login", :action=>"show"}[:controller]+"_controller").classify

Respondido el 09 de enero de 11 a las 00:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.