class Chef::Node::ImmutableArray
ImmutableArray¶ ↑
ImmutableArray is used to implement Array collections when reading node attributes.
ImmutableArray acts like an ordinary Array, except:
-
Methods that mutate the array are overridden to raise an error, making the collection more or less immutable.
-
Since this class stores values computed from a parent Chef::Node::Attribute's values, it overrides all reader methods to detect staleness and raise an error if accessed when stale.
Constants
- DISALLOWED_MUTATOR_METHODS
A list of methods that mutate Array. Each of these is overridden to raise an error, making this instances of this class more or less immutable.
Public Class Methods
new(array_data)
click to toggle source
# File lib/chef/node/immutable_collections.rb, line 69 def initialize(array_data) array_data.each do |value| internal_push(immutablize(value)) end end
Public Instance Methods
dup()
click to toggle source
# File lib/chef/node/immutable_collections.rb, line 95 def dup Array.new(map {|e| safe_dup(e)}) end
safe_dup(e)
click to toggle source
For elements like Fixnums, true, nil…
# File lib/chef/node/immutable_collections.rb, line 89 def safe_dup(e) e.dup rescue TypeError e end
to_a()
click to toggle source
# File lib/chef/node/immutable_collections.rb, line 99 def to_a a = Array.new each do |v| a << case v when ImmutableArray v.to_a when ImmutableMash v.to_hash else v end end a end