Ruby on Rails: what does the => symbol mean?

前端 未结 2 1097
执笔经年
执笔经年 2021-02-01 20:22

I am working my way through Head First Rails, and I keep seeing =>. It\'s in the routes:

map.connect \'/marmots/new\', controller=>\'marmots\',

2条回答
  •  灰色年华
    2021-02-01 21:12

    Your first function call is a shortcut for

    map.connect('/marmots/new', {:controller=>'marmots', :action=>'new'})
    

    where the {} are a Hash-literal. The second argument of the method connect of the object map is an object of class Hash with the two keys :controller and :action (both are literals of the class Symbol) whose corresponding values are the two strings 'marmots' and 'new'.

    EDIT: I call it "arrow" or "maps to".

提交回复
热议问题