Class: Chamber::NamespaceSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/chamber/namespace_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw_namespaces = {}) ⇒ NamespaceSet

Internal: Creates a new NamespaceSet from arrays, hashes and sets.



18
19
20
# File 'lib/chamber/namespace_set.rb', line 18

def initialize(raw_namespaces = {})
  self.namespaces = raw_namespaces
end

Instance Method Details

#+(other) ⇒ Object

Internal: Allows a NamespaceSet to be combined with some other array-like object.

It does not mutate the source NamespaceSet but rather creates a new one and returns it.

Examples:

# Can be an Array
namespace_set = NamespaceSet.new ['value_1', 'value_2']
namespace_set + ['value_3']
# => <NamespaceSet namespaces=['value_1', 'value_2', 'value_3']>

# Can be a Set
namespace_set = NamespaceSet.new ['value_1', 'value_2']
namespace_set + Set['value_3']
# => <NamespaceSet namespaces=['value_1', 'value_2', 'value_3']>

# Can be a object which is convertable to an Array
namespace_set = NamespaceSet.new ['value_1', 'value_2']
namespace_set + (1..3)
# => <NamespaceSet namespaces=['value_1', 'value_2', '1', '2', '3']>

Returns a NamespaceSet



48
49
50
# File 'lib/chamber/namespace_set.rb', line 48

def +(other)
  NamespaceSet.new namespaces + other.to_a
end

#==(other) ⇒ Object

Internal: Determines whether a NamespaceSet is equal to another array-like object.

Returns a Boolean



80
81
82
# File 'lib/chamber/namespace_set.rb', line 80

def ==(other)
  self.to_ary.eql? other.to_ary
end

#eachObject

Internal: Iterates over each namespace value and allows it to be used in a block.



56
57
58
59
60
# File 'lib/chamber/namespace_set.rb', line 56

def each
  namespaces.each do |namespace|
    yield namespace
  end
end

#eql?(other) ⇒ Boolean

Internal: Determines whether a NamespaceSet is equal to another NamespaceSet.

Returns a Boolean

Returns:

  • (Boolean)


90
91
92
93
# File 'lib/chamber/namespace_set.rb', line 90

def eql?(other)
  other.is_a?(        Chamber::NamespaceSet)  &&
  self.namespaces  == other.namespaces
end

#to_aryObject Also known as: to_a

Internal: Converts a NamespaceSet into an Array consisting of the namespace values stored in the set.

Returns an Array



68
69
70
# File 'lib/chamber/namespace_set.rb', line 68

def to_ary
  namespaces.to_a
end