Project

General

Profile

Actions

Feature #20703

closed

Alias StringIO#string to StringIO#to_s/to_str

Feature #20703: Alias StringIO#string to StringIO#to_s/to_str

Added by sebyx07 (Sebastian Buza) about 1 year ago. Updated about 1 year ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:118970]

Description

Description

Allow to use StringIO.new('my string').to_s to be the same as StringIO.new('my string').string

IMO nobody really uses the current StringIO#to_s, so I don't think it will break other apps.

  • Also added .to_str

That way you can also do interpolation easily

my_sio = StringIO.new('my string')

# current
puts "value: #{my_sio}" # value: #<StringIO:0x0000764bba88eec0>

# after
puts "value: #{my_sio}" # value: my string

Updated by sebyx07 (Sebastian Buza) about 1 year ago Actions #1

  • Description updated (diff)

Updated by sebyx07 (Sebastian Buza) about 1 year ago Actions #2

  • Description updated (diff)

Updated by Dan0042 (Daniel DeLorme) about 1 year ago Actions #3 [ruby-core:118971]

+1
Might also consider adding #to_str, as I think it makes sense to consider StringIO to be a kind of string.

Updated by sebyx07 (Sebastian Buza) about 1 year ago Actions #4 [ruby-core:118977]

@Dan0042 done, ty!

Updated by sebyx07 (Sebastian Buza) about 1 year ago Actions #5

  • Subject changed from Alias StringIO#string to StringIO#to_s to Alias StringIO#string to StringIO#to_s/to_str
  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) about 1 year ago Actions #6 [ruby-core:119059]

  • Status changed from Open to Rejected

At this developers' meeting, no one was favor of this.

IMO, StringIO is not a String-like object.

Updated by matz (Yukihiro Matsumoto) about 1 year ago Actions #7 [ruby-core:119062]

Since StringIO is a IO-like object, not String-like object, so it should not provide to_str. And string body of a StringIO tends to be long, so simple alias of string to to_s does not always work well.
So please use string method if you want string body from a StringIO.

Matz.

Actions

Also available in: PDF Atom