首页 > 解决方案 > Ruby - Enumerable::group_by 和空字符串

问题描述

group_by我正在尝试使用如下方法在服务中的单个空键上对数组进行分组

...

def process(array)
  if a_case
    partition = method(:general_entity)
  else
    partition = method(:other_entity)
  end

  array.group_by(&partition)
end

def general_entity(_cells)
  ""
end

def other_entity(_cells)
...

您认为这种方法上的general_entity方法可以安全使用吗?

如果您能分享您的想法或提出更好的方法,那就太好了:D

标签: arraysrubygroup-bygrouping

解决方案


推荐阅读