Bug #11648

Undocumented features of String#oct

Added by mwpastore (Mike Pastore) almost 5 years ago. Updated almost 5 years ago.

Target version:
ruby -v:
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]


String#oct will adjust the base of the stringy number being converted to 2 (if prefixed with 0B), 8 (also the default, if prefixed with 0O), 10 (if prefixed with 0D), or 16 (if prefixed with 0X). Much to my surprise this behavior is not documented at [1]. Is this the intended behavior and if so should the documentation be updated? If it is not the intended behavior, perhaps String#oct should raise an exception if someone tries to use this undocumented feature?


Updated by yugui (Yuki Sonoda) almost 5 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

It is surprising for me too. But this behavior was introduced in r373 by intention.
I hope Matz remembers the original intention.

I guess Ruby followed the behavior of Perl and it was useful to handle string representation of file permissions?


Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

  • Status changed from Open to Closed

Applied in changeset r53122.

string.c: radix indicators [ci skip]

  • string.c (rb_str_oct): [DOC] mention radix indicators. [ruby-core:71310] [Bug #11648]

Also available in: Atom PDF