Commit 011eb580 by liyijie

feat: try_chain 支持 Array

parent 9b68381f
...@@ -205,7 +205,13 @@ module TalltyImportExport ...@@ -205,7 +205,13 @@ module TalltyImportExport
end end
def try_chain record, arr def try_chain record, arr
arr.reduce(record) { |r, m| r.try(:[], m) || r.try(:[], m.to_sym) || r.try(m) } arr.reduce(record) do |r, m|
if r.is_a?(Array)
r.try(:[], m) || r.try(:[], m.to_i) || r.try(m)
else
r.try(:[], m) || r.try(:[], m.to_sym) || r.try(m)
end
end
end end
def try_method record, method, prefix: nil def try_method record, method, prefix: nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment