Module: IOStruct::InspectBase
- Included in:
- DecInspect, HexInspect
- Defined in:
- lib/iostruct.rb
Constant Summary collapse
- INT_MASKS =
{ 1 => 0xff, 2 => 0xffff, 4 => 0xffffffff, 8 => 0xffffffffffffffff }.freeze
Instance Method Summary collapse
-
#inspect ⇒ Object
don’t make inspect an alias to to_s or vice versa, because: - ruby’s default struct inspect() and to_s() returns same result, but they are different methods - inspect/to_s may already be used by some code (zsteg), where aliasing would break things.
- #to_s ⇒ Object
-
#to_table ⇒ Object
rubocop:disable Lint/DuplicateBranch.
Instance Method Details
#inspect ⇒ Object
don’t make inspect an alias to to_s or vice versa, because:
- ruby's default struct inspect() and to_s() returns same result, but they are different methods
- inspect/to_s may already be used by some code (zsteg), where aliasing would break things
189 190 191 |
# File 'lib/iostruct.rb', line 189 def inspect _inspect end |
#to_s ⇒ Object
193 194 195 |
# File 'lib/iostruct.rb', line 193 def to_s _inspect end |
#to_table ⇒ Object
rubocop:disable Lint/DuplicateBranch
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/iostruct.rb', line 163 def to_table values = to_a "<#{IOStruct.get_name(self.class)} " + self.class::FIELDS.map.with_index do |el, idx| v = values[idx] fname, f = el "#{fname}=" + case when f.nil? # unknown field type v.inspect when f.type == Integer v ||= 0 # avoid "`sprintf': can't convert nil into Integer" error format_int(v, f.size, fname) when f.type == Float v ||= 0 # avoid "`sprintf': can't convert nil into Float" error "%8.3f" % v else v.inspect end end.join(' ') + ">" end |