⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.133
Server IP:
185.119.109.197
Server:
Linux managedhosting.chostar.me 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.1.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
3.0.0
/
system
/
Enumerator
/
Lazy
/
View File Name :
cdesc-Lazy.ri
U:RDoc::NormalClass[iI" Lazy:ETI"Enumerator::Lazy;TI"Enumerator;To:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[ I"PEnumerator::Lazy is a special type of Enumerator, that allows constructing ;TI"Nchains of operations without evaluating them immediately, and evaluating ;TI"Rvalues on as-needed basis. In order to do so it redefines most of Enumerable ;TI"Amethods so that they just construct another lazy enumerator.;To:RDoc::Markup::BlankLine o; ;[I"FEnumerator::Lazy can be constructed from any Enumerable with the ;TI"Enumerable#lazy method.;T@o:RDoc::Markup::Verbatim;[I"Xlazy = (1..Float::INFINITY).lazy.select(&:odd?).drop(10).take_while { |i| i < 30 } ;TI"€# => #
:select>:drop(10)>:take_while> ;T:@format0o; ;[I"PThe real enumeration is performed when any non-redefined Enumerable method ;TI"Pis called, like Enumerable#first or Enumerable#to_a (the latter is aliased ;TI"'as #force for more semantic code):;T@o;;[ I"lazy.first(2) ;TI"#=> [21, 23] ;TI" ;TI"lazy.force ;TI"#=> [21, 23, 25, 27, 29] ;T;0o; ;[I"LNote that most Enumerable methods that could be called with or without ;TI">a block, on Enumerator::Lazy will always require a block:;T@o;;[I":[1, 2, 3].map #=> #
;TI"Q[1, 2, 3].lazy.map # ArgumentError: tried to call lazy map without a block ;T;0o; ;[I"UThis class allows idiomatic calculations on long or infinite sequences, as well ;TI"Jas chaining of calculations without constructing intermediate arrays.;T@o; ;[I";Example for working with a slowly calculated sequence:;T@o;;[I"require 'open-uri' ;TI" ;TI"1# This will fetch all URLs before selecting ;TI"# necessary data ;TI"/URLS.map { |u| JSON.parse(open(u).read) } ;TI"- .select { |data| data.key?('stats') } ;TI" .first(5) ;TI" ;TI"2# This will fetch URLs one-by-one, only till ;TI"5# there is enough data to satisfy the condition ;TI"4URLS.lazy.map { |u| JSON.parse(open(u).read) } ;TI"- .select { |data| data.key?('stats') } ;TI" .first(5) ;T;0o; ;[I"IEnding a chain with ".eager" generates a non-lazy enumerator, which ;TI"Iis suitable for returning or passing to another method that expects ;TI"a normal enumerator.;T@o;;[I"def active_items ;TI" groups ;TI" .lazy ;TI" .flat_map(&:items) ;TI" .reject(&:disabled) ;TI" .eager ;TI" end ;TI" ;TI"?# This works lazily; if a checked item is found, it stops ;TI":# iteration and does not look into remaining groups. ;TI"2first_checked = active_items.find(&:checked) ;TI" ;TI"E# This returns an array of items like a normal enumerator does. ;TI"1all_checked = active_items.select(&:checked);T;0: @fileI"enumerator.c;T:0@omit_headings_from_table_of_contents_below0; 0;0[ [ [ [[I" class;T[[:public[[I"new;TI"enumerator.c;T[:protected[ [:private[ [I" instance;T[[;[3[I"_enumerable_collect;T@h[I"_enumerable_collect_concat;T@h[I"_enumerable_drop;T@h[I"_enumerable_drop_while;T@h[I"_enumerable_filter;T@h[I"_enumerable_filter_map;T@h[I"_enumerable_find_all;T@h[I"_enumerable_flat_map;T@h[I"_enumerable_grep;T@h[I"_enumerable_grep_v;T@h[I"_enumerable_map;T@h[I"_enumerable_reject;T@h[I"_enumerable_select;T@h[I"_enumerable_take;T@h[I"_enumerable_take_while;T@h[I"_enumerable_uniq;T@h[I"_enumerable_zip;T@h[I" chunk;T@h[I"chunk_while;T@h[I"collect;T@h[I"collect_concat;T@h[I" drop;T@h[I"drop_while;T@h[I" eager;T@h[I" enum_for;T@h[I"filter;T@h[I"filter_map;T@h[I" find_all;T@h[I" flat_map;T@h[I" force;T@h[I" grep;T@h[I"grep_v;T@h[I" lazy;T@h[I"map;T@h[I"reject;T@h[I"select;T@h[I"slice_after;T@h[I"slice_before;T@h[I"slice_when;T@h[I" take;T@h[I"take_while;T@h[I" to_a;T@h[I"to_enum;T@h[I" uniq;T@h[I"with_index;T@h[I"zip;T@h[;[ [;[[I"_enumerable_with_index;T@h[ [U:RDoc::Context::Section[i 0o;;[ ; 0;0[@\@ cRDoc::NormalClass