--Apple-Mail-1--30292949 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset -ASCII; formatðïwed Begin forwarded message: > From: afalcone / tinymonkey.net > Date: July 31, 2006 1:17:10 PM CDT > To: submission / rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission (88) > > Hi James. Please forward my solution on to the board. > > Thanks, > -Adrian --Apple-Mail-1--30292949 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode66; namep8.rb Content-Disposition: attachment; filename¥¿ip8.rb class UnsignedFixedWidthInt #code for this class taken from Hank Lords' solution to ruby quiz #85 #http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/199907 # #to_bin_string is mine #Direct access to @value added to assist carry and certain quicker assignments. #Kinda defeats the purpose of using this class, but I save on object creation in certain places # -AF attr_accessor :value def initialize(value, bits) raise ArgumentError.new('number of bits must be > 0') if bits < @bits its @value alue % 2**@bits end # operators returning a new FixedWidthInt %w{& ^ | << >> + - * / +@ -@ ~@}.each do |operator| define_method operator do |*other| self.class.new(@value.send(operator, *other), @bits) end end # methods forwarded to @value %w{ < > <