Project

General

Profile

Feature #11300

[PATCH] Add String#bin for parity with #hex and #oct.

Added by 0x0dea (D.E. Akers) about 4 years ago. Updated 30 days ago.

Status:
Feedback
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:69719]

Description

Proposal

It is proposed that String#bin be added to return the receiver's value when interpreted as a string of binary digits.

Rationale

This method's absence is surprising in the presence of #hex and #oct.


Files

string_bin.patch (2.17 KB) string_bin.patch 0x0dea (D.E. Akers), 06/24/2015 01:00 AM

History

Updated by matz (Yukihiro Matsumoto) about 4 years ago

  • Status changed from Open to Feedback

Two points. Unlike #hex and #oct, there's little demand for 0/1 strings conversion.
Besides that, String#bin can be easily confused with "binary (raw) encoding" and cause more surprise.
Any opinion?

Matz.

Updated by normalperson (Eric Wong) about 4 years ago

matz@ruby-lang.org wrote:

Two points. Unlike #hex and #oct, there's little demand for 0/1 strings conversion.
Besides that, String#bin can be easily confused with "binary (raw) encoding" and cause more surprise.
Any opinion?

I agree it is potentially confusing with String#b and redundant.

I even wish redundant methods like String#hex and String#oct can go away,
too; String#to_i is enough.

#3

Updated by jeremyevans0 (Jeremy Evans) 30 days ago

  • Backport deleted (2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN)
  • Tracker changed from Bug to Feature

Also available in: Atom PDF