gpt4 book ai didi

ruby-on-rails - Ruby 自定义方法链

转载 作者:行者123 更新时间:2023-12-03 15:34:11 24 4
gpt4 key购买 nike

将多个自定义方法链接在一起的最佳方式是什么?我想以一种优雅的方式将我的方法的输出直接放入下一个方法中。下面的第一个是我现在所拥有的。

verified = search_verified(@providers)
matching = search_matching(verified)
deactivated = search_deactivated(matching)
networks = search_networks(deactivated)
designations = search_designations(networks)
disorders = search_disorders(designations)
age_groups = search_age_groups(disorders)
governing = search_governing(age_groups)
search_availabilities(governing)
也许更多的是:
search_verified(@providers) 
>> search_matching
>> search_deactivated
>> search_networks
>> ....

最佳答案

您可能想使用 then 链接您的方法和 numbers parameter简化块:

search_verified(@providers)
.then { search_matching(_1) }
.then { search_deactivated(_1) }
.then { search_networks(_1) }
.then { search_designations(_1) }
.then { search_disorders(_1) }
.then { search_age_groups(_1) }
.then { search_governing(_1) }
.then { search_availabilities(_1) }

关于ruby-on-rails - Ruby 自定义方法链,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67113813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com