Jupp wrote:
> Does "write a class" imply that UnsignedFixedWidthInt and
> SignedFixedWidthInt are two different names for the just one class?

This is my first quiz submission for a while. This question is what
intrigued me, actually.

In C, an unsigned int is a different type to an unsigned long long.
Therefore, my solution provides a mechanism for generating these
subtypes: one class for each distinct combination of size and either
signed or unsigned, which all share the parent class FixedWidthInt.

Here's what the code that uses this library looks like:

  UInt32 = FixedWidthInt.type(:unsigned, 32)  # define a new int type
  i = UInt32.get(42)                          # get instance of the type
  i == 42 #=> true

  j = FixedWidthInt.get(:unsigned, 32, 86)  # no explicit type in call
  j.kind_of? UInt32 #=> true                # but result type is same

  k = UnsignedFixedWidthInt.new(0xFF00FF00, 32) # quiz compatible syntax
  k.kind_of? UnsignedFixedWidthInt #=> true
  k.kind_of? UInt32 #=> true

My solution is not well-tested, and is pretty much guaranteed to have
some bugs due to the way it uses method_missing to delegate to an
underlying Integer. I also threw in Mauricio Fernandez' WeakHash (an
improved version to work with Bignum values) for the heck of it.

Here's the code:

http://dave.burt.id.au/ruby/fixed_width_ints.rb
http://dave.burt.id.au/ruby/weak_hash.rb

Cheers,
Dave