From: Gregory Brown Date: 2009-08-12T23:12:06+09:00 Subject: [ruby-core:24885] IDEA: Shortcut syntax for binary strings? Hey folks, Just brainstorming (and chatting w. JEG2) about some m17n issues and came across a relatively simple feature that might be nice to have. One challenge right now is easily working with binary strings when the source encoding is not ASCII-8BIT. For example: # encoding: UTF-8 puts "Welcome to GIF Builder�" bin_data = "".force_encoding("BINARY") bin_data << "GIF".force_encoding("BINARY") # needed to prevent up-cast to UTF-8 Now, I've been able to work around issues like this in Prawn and other code of mine by isolating binary code as much as possible and handling encoding conversion in functions and the like, but it might make things a little easier if we have a shortcut syntax for this. The same example could be recast as something like: # encoding: UTF-8 puts "Welcome to GIF Builder�" bin_data = %b{} bin_data << %b{GIF} Or, if we didn't want new syntax, something like: class String def bin force_encoding("BINARY") end end However, new syntax would make the strings visually identifiable immediately, helping the programmer spot potential problems. What do you think? -greg