class MiniObject::IndexedList
Public Class Methods
new()
click to toggle source
# File lib/mini_object/indexed_list.rb, line 7 def initialize @store = {} end
Public Instance Methods
<<(e)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 19 def << e store[key_for(e)] = e end
Also aliased as: add
[](key)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 31 def [] key store.values.detect {|e| key_for(e) == key } end
add_new(&block)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 25 def add_new &block e = build_new ForwardingDsl.run e, &block add e end
build(&block)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 15 def build &block @build_proc = block end
clear()
click to toggle source
# File lib/mini_object/indexed_list.rb, line 39 def clear store.clear end
each(&block)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 35 def each &block store.values.each &block end
empty?()
click to toggle source
# File lib/mini_object/indexed_list.rb, line 62 def empty? store.empty? end
initialize_dup(source)
click to toggle source
Calls superclass method
# File lib/mini_object/indexed_list.rb, line 53 def initialize_dup(source) @store = store.dup super end
key(&block)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 11 def key &block @key_proc = block end
last()
click to toggle source
# File lib/mini_object/indexed_list.rb, line 58 def last store.values.last end
merge(other)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 43 def merge other new = dup other.each do |v| new << v end new end
Private Instance Methods
build_new(*args)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 76 def build_new *args @build_proc.call *args end
key_for(e)
click to toggle source
# File lib/mini_object/indexed_list.rb, line 72 def key_for e @key_proc.call e end
store()
click to toggle source
# File lib/mini_object/indexed_list.rb, line 68 def store @store end