Module: Tinycode::FixedInteger

Included in:
U16, U32, U64, U8
Defined in:
lib/tinycode/fixed_integer.rb

Overview

Mixin module for U8, U16, U32, and U64 classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject (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

Raises:

  • (ArgumentError)


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

#inspectObject



26
27
28
# File 'lib/tinycode/fixed_integer.rb', line 26

def inspect
  "#<#{self.class} value=#{value.inspect}>"
end

#tinycodeObject



18
19
20
# File 'lib/tinycode/fixed_integer.rb', line 18

def tinycode
  Tinycode.dump(self)
end

#to_sObject



22
23
24
# File 'lib/tinycode/fixed_integer.rb', line 22

def to_s
  value.to_s
end