Module: Tinycode::FixedInteger
Overview
Mixin module for U8, U16, U32, and U64 classes
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #to_i, #to_int)
readonly
Returns the value of attribute value.
Instance Method Summary collapse
Instance Attribute Details
#value ⇒ Object (readonly) Also known as: to_i, to_int
Returns the value of attribute value.
6 7 8 |
# File 'lib/tinycode/fixed_integer.rb', line 6 def value @value end |
Instance Method Details
#==(other) ⇒ Object
30 31 32 |
# File 'lib/tinycode/fixed_integer.rb', line 30 def ==(other) value == other.value end |
#initialize(value) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/tinycode/fixed_integer.rb', line 10 def initialize(value) raise ArgumentError, "#{value.class} cannot be converted to integer" unless value.respond_to?(:to_int) @value = value.to_int raise RangeError, "#{@value.inspect} out of range for #{self.class}" unless self.class.range.include?(@value) end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/tinycode/fixed_integer.rb', line 26 def inspect "#<#{self.class} value=#{value.inspect}>" end |
#tinycode ⇒ Object
18 19 20 |
# File 'lib/tinycode/fixed_integer.rb', line 18 def tinycode Tinycode.dump(self) end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/tinycode/fixed_integer.rb', line 22 def to_s value.to_s end |