Module: Xen::Parentable

Included in:
Backup, ConfigFile, Instance
Defined in:
lib/ruby-xen.rb

Overview

DRY up some classes (children of Slice) with some module funkiness.

Instance Method Summary collapse

Instance Method Details

#sliceObject

Returns the parent Slice object (d) for a sub-object. We ensure d.instance.object_id == self.object_id

Example

i = Xen::Instance.all[2]
s = i.slice
i.object_id == s.instance.object_id # true


97
98
99
100
101
102
# File 'lib/ruby-xen.rb', line 97

def slice
  d = Xen::Slice.new(:name => name)
  # Insert the current object into the newly created Slice's attributes
  d.instance_variable_set("@#{self.class.to_s.sub('Xen::','').downcase}", self)
  d
end