看板 Ruby 關於我們 聯絡資訊
arr = [1, 2, 3] arr.map(&:to_s) # => ["1", "2", "3"] arr.map(&:class) # => [Fixnum, Fixnum, Fixnum] 大概可以看出這樣的語法等同於 arr.map {|f| f.to_s} / arr.map {|f| f.class} 只是我不太懂為甚麼可以作這樣的 shortcut? 這是本來就有的功能,還是可以從語法的層面解釋呢? 謝謝 m(_ _)m -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.117.1.160
suomax:自問自答 是因為 ActiveSupport 替 Symbol 加上 to_proc 09/01 01:46
※ 編輯: suomax 來自: 59.117.1.160 (09/01 01:46)