Actions
Bug #1681
closedInteger#chr Should Infer Encoding of Given Codepoint
    Bug #1681:
    Integer#chr Should Infer Encoding of Given Codepoint
  
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux]
Backport:
Description
=begin
String#ord and Integer#chr are symmetrical operations on ASCII Strings:
 'a'.ord.chr   #=> "a"
But Integer#chr fails to round-trip when the given codepoint is outside the range of ASCII:
 "\u{2563}".ord.chr #=> RangeError: 9571 out of char range
To fix this, the codepoint's encoding needs to be specified:
 "\u{2563}".ord.chr('utf-8')  #=> "╣"
This seems needlessly verbose given that Ruby already knows that my source encoding is UTF-8. I suggest, then, that, when invoked with no argument, Integer#chr displays the given codepoint w.r.t to the current encoding, raising a RangeError only if the codepoint is out-of-bounds for this inferred encoding.
=end
Actions