Sha256: e040b3d11838b11184c5fe1955288f78bcdb8830c2ec442fb09e73d3153bff50

Contents?: true

Size: 915 Bytes

Versions: 43

Compression:

Stored size: 915 Bytes

Contents

#!/usr/bin/env ruby

# 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

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/struct2/element.rb
librex-0.0.63 lib/rex/struct2/element.rb
librex-0.0.54 lib/rex/struct2/element.rb
librex-0.0.53 lib/rex/struct2/element.rb
librex-0.0.52 lib/rex/struct2/element.rb
librex-0.0.51 lib/rex/struct2/element.rb
librex-0.0.50 lib/rex/struct2/element.rb
librex-0.0.49 lib/rex/struct2/element.rb
librex-0.0.48 lib/rex/struct2/element.rb
librex-0.0.47 lib/rex/struct2/element.rb
librex-0.0.46 lib/rex/struct2/element.rb
librex-0.0.44 lib/rex/struct2/element.rb
librex-0.0.43 lib/rex/struct2/element.rb
librex-0.0.42 lib/rex/struct2/element.rb
librex-0.0.41 lib/rex/struct2/element.rb
librex-0.0.40 lib/rex/struct2/element.rb
librex-0.0.39 lib/rex/struct2/element.rb
librex-0.0.38 lib/rex/struct2/element.rb
librex-0.0.37 lib/rex/struct2/element.rb
librex-0.0.36 lib/rex/struct2/element.rb