[問題] 問個語法問題
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
→
09/01 01:46, , 1F
09/01 01:46, 1F
※ 編輯: suomax 來自: 59.117.1.160 (09/01 01:46)