⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.93
Server IP:
65.108.141.171
Server:
Linux server.heloix.com 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
2.7.0
/
system
/
Object
/
Edit File: to_enum-i.ri
U:RDoc::AnyMethod[iI"to_enum:ETI"Object#to_enum;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"JCreates a new Enumerator which will enumerate by calling +method+ on ;TI"H+obj+, passing +args+ if any. What was _yielded_ by method becomes ;TI"values of enumerator.;To:RDoc::Markup::BlankLine o; ; [I"CIf a block is given, it will be used to calculate the size of ;TI"Ithe enumerator without the need to iterate it (see Enumerator#size).;T@S:RDoc::Markup::Heading: leveli: textI" Examples;T@o:RDoc::Markup::Verbatim; [I"str = "xyz" ;TI" ;TI"%enum = str.enum_for(:each_byte) ;TI"enum.each { |b| puts b } ;TI"# => 120 ;TI"# => 121 ;TI"# => 122 ;TI" ;TI";# protect an array from being modified by some_method ;TI"a = [1, 2, 3] ;TI"some_method(a.to_enum) ;TI" ;TI"<# String#split in block form is more memory-effective: ;TI"Uvery_large_string.split("|") { |chunk| return chunk if chunk.include?('DATE') } ;TI"@# This could be rewritten more idiomatically with to_enum: ;TI"Dvery_large_string.to_enum(:split, "|").lazy.grep(/DATE/).first ;T:@format0o; ; [I"=It is typical to call to_enum when defining methods for ;TI"6a generic Enumerable, in case no block is passed.;T@o; ; [I"HHere is such an example, with parameter passing and a sizing block:;T@o;; [I"module Enumerable ;TI"A # a generic method to repeat the values of any enumerable ;TI" def repeat(n) ;TI"; raise ArgumentError, "#{n} is negative!" if n < 0 ;TI" unless block_given? ;TI"I return to_enum(__method__, n) do # __method__ is :repeat here ;TI"< sz = size # Call size and multiply by n... ;TI"B sz * n if sz # but return nil if size itself is nil ;TI" end ;TI" end ;TI" each do |*val| ;TI"" n.times { yield *val } ;TI" end ;TI" end ;TI" end ;TI" ;TI".%i[hello world].repeat(2) { |w| puts w } ;TI"6 # => Prints 'hello', 'hello', 'world', 'world' ;TI"enum = (1..14).repeat(3) ;TI"> # => returns an Enumerator when called without a block ;TI"%enum.first(4) # => [1, 1, 1, 2] ;TI"enum.size # => 42;T;0: @fileI"enumerator.c;T:0@omit_headings_from_table_of_contents_below0I"zobj.to_enum(method = :each, *args) -> enum obj.to_enum(method = :each, *args) {|*args| block} -> enum;T0[ I"(*args);T@HFI"Object;TcRDoc::NormalClass00
Simpan