gpt4 book ai didi

ruby - 切片 vs 提取!轨道 5

转载 作者:行者123 更新时间:2023-12-04 02:28:42 24 4
gpt4 key购买 nike

我今天对一个旧代码进行了一些审查,出现了这个问题,如果提前道歉,这可能是一个愚蠢的问题,但是 slice 和 extract 之间有什么真正的区别!函数(对于哈希),我查看了文档,它们之间没有明显的区别(至少对我而言):

也没有在社区上找到任何东西,提前谢谢。

最佳答案

slice方法返回包含所选元素的新哈希。这会保留原始对象。

extract!方法从原始散列中删除这些条目 并返回提取的元素。这会改变原始对象。

Note: In many cases Ruby methods ending in ! alter the object they're called on as opposed to similar methods which do not have that extension where a new object is returned.

不同之处需要仔细阅读文档,其中 extract! 方法被描述为:

Removes and returns the key/value pairs matching the given keys.

这里的“删除”是区别符。

关于ruby - 切片 vs 提取!轨道 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65605271/

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