From: matthew@... Date: 2018-03-04T03:22:36+00:00 Subject: [ruby-core:85914] [Ruby trunk Feature#14574] percent literals and binary encoding strings Issue #14574 has been updated by phluid61 (Matthew Kerwin). ~~~ruby str = "\x00".b #=> "\x00" str.encoding #=> # ~~~ Incidentally, if you care about it: ~~~ruby str = -"...".b str.frozen? #=> true str.encoding #=> # ~~~ ---------------------------------------- Feature #14574: percent literals and binary encoding strings https://bugs.ruby-lang.org/issues/14574#change-70770 * Author: pb (pumbur _) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- coding `"\x00".force_encoding('binary')` or `["\x00"].pack('a*')` is a hassle, is there a chance to have special percent literal for it? i.e: `%b"\x00"` would return binary string. (note, signle-character \x00 there is accidental, the idea is force any string from script encoding to binary) or, more general suggestion: allow percent literal with any [a-z] character, move all logic to user-level and allow it to be redefinable: ~~~ ruby define_percent_literal(:b){|q| q.force_encoding('binary') } %b'\x00' #=> "\x00" ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: