Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
class Array # Converts hex input to pack("C*") (binary) output. Hex can be any of: # # [65,65,65].binarize #=> "AAA" # Decimal notation # [0x41,0x41,0x41].binarize #=> "AAA" # Hex notation # %w{41 41 41}.binarize #=> "AAA" # Strings of hex notation # [0x41,"41",0x41].binarize #=> "AAA" # Mixed fixnums and strings # "414141".binarize #=> "AAA" # Extension to String, below. def binarize self.collect {|x| (x.class == String) ? x.to_i(16) : x}.pack("C*") end end class String # Converts hex input (string format) to packed output. See Array#binarize. def binarize self.scan(/../).binarize end end
This paste will be private.
From the Design Piracy series on my blog: