Sha256: 7ba0df23e3548e7f09fe3d76035dec705ef6f8ee9ff052860f5c068d985cd5d8

Contents?: true

Size: 965 Bytes

Versions: 20

Compression:

Stored size: 965 Bytes

Contents

# -*- coding: binary -*-

# Rex::Struct2
module Rex
module Struct2

module Element

  # elements should have to_s, but we don't define it here because
  # it will just overlap with inheritence and cause issues

  attr_reader  :value, :restraint, :container
  attr_writer  :restraint, :container

  # update the restraints on any value change
  def value=(newval)
    @value = newval
    self.update_restraint
  end

  # avoid conflicting with normal namespace length()
  def slength
    to_s().length()
  end

  def update_restraint
    if self.restraint
      # Sort of a hack, but remove the restraint before we update, so we aren't using
      # the old restraint during calculating the restraint update value
      old_restraint, self.restraint = self.restraint, nil
      old_restraint.update(self.slength)
      self.restraint = old_restraint
    end

    if self.container
      self.container.update_restraint
    end
  end

end

# end Rex::Struct2
end
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
rex-struct2-0.1.4 lib/rex/struct2/element.rb
rex-struct2-0.1.3 lib/rex/struct2/element.rb
rex-2.0.13 lib/rex/struct2/element.rb
rex-2.0.12 lib/rex/struct2/element.rb
rex-2.0.11 lib/rex/struct2/element.rb
rex-struct2-0.1.2 lib/rex/struct2/element.rb
rex-struct2-0.1.1 lib/rex/struct2/element.rb
rex-struct2-0.1.0 lib/rex/struct2/element.rb
rex-2.0.10 lib/rex/struct2/element.rb
rex-2.0.9 lib/rex/struct2/element.rb
rex-2.0.8 lib/rex/struct2/element.rb
rex-2.0.7 lib/rex/struct2/element.rb
rex-2.0.5 lib/rex/struct2/element.rb
rex-2.0.4 lib/rex/struct2/element.rb
dstruct-0.0.1 lib/rex/struct2/element.rb
rex-2.0.3 lib/rex/struct2/element.rb
librex-0.0.999 lib/rex/struct2/element.rb
rex-2.0.2 lib/rex/struct2/element.rb
librex-0.0.71 lib/rex/struct2/element.rb
librex-0.0.70 lib/rex/struct2/element.rb