module Brice::History::Tee

Public Class Methods

extended(base) click to toggle source
    # File lib/brice/history.rb
128 def self.extended(base)
129   class << base
130     alias_method :push_without_tee,   :<<
131     alias_method :push_m_without_tee, :push
132 
133     alias_method :<<,   :push_with_tee
134     alias_method :push, :push_m_with_tee
135   end
136 end

Public Instance Methods

push_m_with_tee(*args) click to toggle source
    # File lib/brice/history.rb
155 def push_m_with_tee(*args)
156   _tee_delete(*args)
157 
158   tee.concat(args)
159   push_m_without_tee(*args)
160 end
push_with_tee(arg) click to toggle source
    # File lib/brice/history.rb
148 def push_with_tee(arg)
149   _tee_delete(arg)
150 
151   tee << arg
152   push_without_tee(arg)
153 end
tee() click to toggle source
    # File lib/brice/history.rb
138 def tee
139   @tee ||= []
140 end
tee!() { |tee| ... } click to toggle source
    # File lib/brice/history.rb
142 def tee!
143   yield tee
144 ensure
145   tee.clear
146 end

Private Instance Methods

_tee_delete(*args) click to toggle source
    # File lib/brice/history.rb
164 def _tee_delete(*args)
165   args.each { |arg| tee.delete(arg) }
166 
167   indexes = []
168 
169   each_with_index { |line, index|
170     indexes << index if args.include?(line)
171   }
172 
173   indexes.reverse_each { |index| delete_at(index) }
174 end