< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Hello,
I would really love to have a cyclic version of each_cons in Ruby --
I found the version below, which seems to work fine for me. I think that
method is not too exotic, so it may be good to have this built in.
https://www.ruby-forum.com/topic/106362
module Enumerable
def each_cycle(window, start=0)
wrap_start = []
cache = []
each_with_index do |e,i|
cache << e
if i >= start + (window - 1)
yield cache[start, window]
cache.shift
else
wrap_start << e
end
end
wrap_start.each do |e|
cache << e
yield cache[start, window]
cache.shift
end
self
end
end
Then you can each_cycle anything that is Enumerable, like a Range:
>> (1..5).each_cycle(3) {|x| p x}
[1, 2, 3]
[2, 3, 4]
[3, 4, 5]
[4, 5, 1]
[5, 1, 2]
=> 1..5
>> { 'dog' => 'Rover', 'cat' => 'Mittens', 'fish' =>
'Goldie' }.each_cycle(2) {|x| p x}
[["cat", "Mittens"], ["fish", "Goldie"]]
[["fish", "Goldie"], ["dog", "Rover"]]
[["dog", "Rover"], ["cat", "Mittens"]]
=> {"cat"=>"Mittens", "fish"=>"Goldie", "dog"=>"Rover"}