Module: IOStruct::HexInspect

Defined in:
lib/iostruct.rb

Overview

InstanceMethods

Instance Method Summary collapse

Instance Method Details

#inspectObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/iostruct.rb', line 132

def inspect
  @fmtstr ||= "<#{self.class.to_s} " + self.class.const_get('FIELDS').map do |name, f|
    fmt =
      case 
      when f.type == Integer
        "%#{f.size*2}x"
      when f.type == Float
        "%8.3f"
      else
        "%s"
      end
    "#{name}=#{fmt}"
  end.join(' ') + ">"
  sprintf @fmtstr, *to_a.map{ |v| v.is_a?(String) ? v.inspect : v }
end