Ruby to_enumで配列をEnumeratorとして返す方法

環境
Windows10 Home 64bit
ruby 3.1.2p20

構文
配列名.to_enum
to_enumを使用して配列をEnumeratorとして返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cft = [61, 76, 83, 98, 90]
p cft.to_enum
p cft
cft = [61, 76, 83, 98, 90] p cft.to_enum p cft
cft = [61, 76, 83, 98, 90]

p cft.to_enum

p cft

実行結果
#<Enumerator: [61, 76, 83, 98, 90]:each>
[61, 76, 83, 98, 90]

Ruby

Posted by arkgame