Class: KO::Children

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ko/children.rb

Instance Method Summary collapse

Constructor Details

#initializeChildren

Returns a new instance of Children.



7
8
9
# File 'lib/ko/children.rb', line 7

def initialize
  @store = {}
end

Instance Method Details

#[](id) ⇒ Object

TODO: use index



12
# File 'lib/ko/children.rb', line 12

def [](id) = @store.find { _1.id == id }

#add(obj) ⇒ Object



14
# File 'lib/ko/children.rb', line 14

def add(obj) = @store[obj] = obj

#countObject



28
# File 'lib/ko/children.rb', line 28

def count(...) = @store.count(...)

#eachObject



27
# File 'lib/ko/children.rb', line 27

def each(...) = @store.each_key(...)

#inspectObject



24
# File 'lib/ko/children.rb', line 24

def inspect = to_a.inspect

#pretty_inspectObject



25
# File 'lib/ko/children.rb', line 25

def pretty_inspect = to_a.pretty_inspect

#remove(obj) ⇒ Object

Raises:



16
17
18
19
20
# File 'lib/ko/children.rb', line 16

def remove(obj)
  raise UnknownChildError unless @store.include?(obj)

  @store.delete(obj)
end

#to_aObject



22
# File 'lib/ko/children.rb', line 22

def to_a = @store.keys