logo
  • 教程列表
  • SO官方文檔
  • 解構
    • 概述
    • 解構塊引數
  1. StackOverflow 文件
  2. Ruby Language 教程
  3. 解構
  4. 解構塊引數

解構塊引數

Created: November-22, 2018

triples = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

triples.each { |(first, second, third)| puts second }
# 2
# 5
# 8

triples.map { |(first, *rest)| rest.join(' ') } # => ["2 3", "5 6", "8 9"]
  • 概述

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明