返回顶部

收藏

Divide with block

更多
require 'set'

s = %w[ant ape cow hen hog].to_set # A set of words

s.divide {|x,y| x[0] == y[0]}      # Divide into subsets by first letter

# => #<Set:{#<Set:{'hog', 'hen'}>, #<Set:{'cow'}>, #<Set:{'ape', 'ant'}>}>

标签:Ruby,集合

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2016-02-04 11:37:45Collect in place by 永明
  2. 2016-04-24 14:08:00Map elements in a set by digua
  3. 2016-08-28 09:29:05Sort on two arrays by jeffsui
  4. 2016-08-28 13:17:44Convert a hash to set and divide by zetaliang
  5. 2016-09-20 09:21:04Divide a set by absolute value by 好好学习啊
  6. 2016-04-24 14:16:11Create Your stack by Loli控
  7. 2016-08-28 09:48:44extend Forwardable by 好好学习啊
  8. 2016-08-28 13:39:21Add set operation to Array by 永明
  9. 2016-09-03 12:08:57Writing Block Methods that Classify or Collect by Jamin
  10. 2016-11-19 09:06:23Building a Histogram by Ω油菜
  11. 2015-12-19 11:02:24Custom class based range by JustForFly

发表评论