Why is the splat used inside an array definition here?

前端 未结 3 1133
天涯浪人
天涯浪人 2021-01-05 20:26
def initialize(apps, catch=404)
  @apps = []; @has_app = {}
  apps.each { |app| add app }

  @catch = {}
  [*catch].each { |status| @catch[status] = true }
end
         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 21:29

    Another way to look at it: an l-value splat is greedy and contains as many corresponding r-values as possible.

提交回复
热议问题