Class: Build::Dependency::Set

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/build/dependency/set.rb

Overview

Very similar to a set but uses a specific callback (defaults to &:name) for object identity.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents = []) ⇒ Set

Returns a new instance of Set.



29
30
31
32
33
34
35
# File 'lib/build/dependency/set.rb', line 29

def initialize(contents = [])
	@table = {}
	
	contents.each do |object|
		add(object)
	end
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



37
38
39
# File 'lib/build/dependency/set.rb', line 37

def table
  @table
end

Instance Method Details

#add(object) ⇒ Object Also known as: <<



59
60
61
62
63
64
65
# File 'lib/build/dependency/set.rb', line 59

def add(object)
	if include?(object)
		raise KeyError, "Object #{identity(object)} already exists!"
	end
	
	@table[identity(object)] = object
end

#delete(object) ⇒ Object



69
70
71
# File 'lib/build/dependency/set.rb', line 69

def delete(object)
	@table.delete(identity(object))
end

#each(&block) ⇒ Object



77
78
79
# File 'lib/build/dependency/set.rb', line 77

def each(&block)
	@table.each_value(&block)
end

#freezeObject



43
44
45
46
47
48
49
# File 'lib/build/dependency/set.rb', line 43

def freeze
	return self if frozen?
	
	@table.freeze
	
	super
end

#identity(object) ⇒ Object



55
56
57
# File 'lib/build/dependency/set.rb', line 55

def identity(object)
	object.name
end

#include?(object) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/build/dependency/set.rb', line 73

def include?(object)
	@table.include?(identity(object))
end

#initialize_dup(other) ⇒ Object



51
52
53
# File 'lib/build/dependency/set.rb', line 51

def initialize_dup(other)
	@table = other.table.dup
end

#slice(names) ⇒ Object



81
82
83
# File 'lib/build/dependency/set.rb', line 81

def slice(names)
	names.collect{|name| @table[name]}
end