|
so this is horribly non-idiomatic ruby, but it was fun p ->(*_) {
_.reduce({}, :merge).tap { |_| return "<none>" if _.empty? }.keys.uniq.map(&:to_s).sort.join(", ")
}.({c:3,d:4,b:2}, {f:5,e:4,a:1})
p ->(*_) {
_.reduce({}, :merge).tap { |_| return "<none>" if _.empty? }.keys.uniq.map(&:to_s).sort.join(", ")
}.({}, {})
# "a, b, c, d, e, f"
# "<none>"
edit: a little bit better. func = ->(*_) {
return "<none>" if _.all?(&:empty?)
_.flat_map(&:keys).uniq.map(&:to_s).sort.join(", ")
}
func.({c:3,d:4,b:2}, {f:5,e:4,a:1})
#=> "a, b, c, d, e, f"
func.({}, {})
#=> "<none>"
https://gist.github.com/66b45e765a2aa6a97143 |