What does & in front of symbol do for a map iterator?

Hey all,

In this line:

visits.map(&:visit_status_id).max == VisitState.get(state).id

I’m just curious what that ampersand is doing there and its relevance to
being passed into map with the symbol.

Also, when you specify a has_many :visits, for example, will that create
a local variable in the model called visits, which contains the
collection of records from the visits table?

Thanks for response

  1. That’s the “Symbol#to_proc” shortcut:

http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html

  1. A has_many declaration will create methods for you (not a local
    variable.)
  1. A has_many declaration will create methods for you (not a local
    variable.)

thanks for response

But if visits is a method, how can you call map on it? Map can only be
called on enumerables like array, string, and hash, right? Or does the
visits method return an array of visit records and if the returned value
is an array, then map is called on that array