Module: Snow::InspectSupport
- Included in:
- Mat3, Mat3Array, Mat4, Mat4Array, Quat, QuatArray, Vec2, Vec2Array, Vec3, Vec3Array, Vec4, Vec4Array
- Defined in:
- lib/snow-math/inspect.rb
Overview
Provides support for inspect calls on Snow math types.
Instance Method Summary collapse
-
#inspect ⇒ Object
Returns a serializable string for a given type.
Instance Method Details
#inspect ⇒ Object
Returns a serializable string for a given type.
Output is defined as ‘<Type:Address Elements>`. For example:
Vec4[1, 2, 3, 4] # => <Snow::Vec4:0x7f831981f5e0 1.0 2.0 3.0 4.0>
# The following example inner Vec3's elements have been made 0.0 even
# though they would ordinarily be garbage values.
Vec3Array[1] # => <Snow::Vec3Array:0x7fe193b297a0 <Snow::Vec3:0x7fe193b297a0 0.0 0.0 0.0>>
Bear in mind that the address may not be useful for serialization beyond determining when a given object has already been deserialized. You may want to treat it as semi-unique ID if serializing a math object, though there is absolutely no guarantee it will be unique between allocations and deallocations, as memory may obviously be reused.
32 33 34 |
# File 'lib/snow-math/inspect.rb', line 32 def inspect "<#{self.class.name}:0x#{self.address.to_s(16)} #{(0 ... self.length).map { |i| self.fetch(i).inspect }.join(' ')}>" end |