Module: Gdsii::Access::EnumerableGroup

Includes:
Enumerable
Included in:
Properties, Structures
Defined in:
lib/gdsii/mixins.rb

Overview

Mix in methods that work with a predefined @list attribute. The list is made Enumerable and a number of methods are mixed in. Used in Properties, Structure, and Library.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *args) ⇒ Object

Implement a trap for a method that might be missing. Any method not listed here will default to the @list Array attribute if @list #respond_to? the method. This nifty feature allows us to “inherit” all methods related Array which will be operated upon the @list Array attribute.



245
246
247
248
249
250
251
252
253
# File 'lib/gdsii/mixins.rb', line 245

def method_missing(method_sym, *args)
  if @list.respond_to?(method_sym)
    # The array @list responds to this method - use it on @list
    @list.method(method_sym).call(*args)
  else
    # Raise the #method_missing error
    super
  end
end

Instance Method Details

#add(object) ⇒ Object

Add an object to this list as either an object instance or as the object data. Similar to Array#push but validates the data being added. The object added is returned.



224
225
226
227
228
# File 'lib/gdsii/mixins.rb', line 224

def add(object)
  self.validate_addition(object) if self.respond_to?(:validate_addition)
  @list.push object
  object
end

#eachObject

Loops through each object yielding along the way.



217
# File 'lib/gdsii/mixins.rb', line 217

def each(); @list.each {|e| yield e}; end

#listObject Also known as: to_a

Get the list object.



210
# File 'lib/gdsii/mixins.rb', line 210

def list() @list; end

#removeObject

Remove object(s) from this element when the propert(y/ies) match the given criteria (in the code block). Equivalent to Array#reject!.



234
235
236
# File 'lib/gdsii/mixins.rb', line 234

def remove()
  @list.reject! {|e| yield e}
end