Project

General

Profile

Feature #10237

Transform all elements of one Encoding into another Encoding for Array and Hash

Added by shevegen (Robert A. Heiler) over 4 years ago. Updated over 1 year ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:65020]

Description

I find myself to sometimes have to convert one encoding to the other.

For string objects, this is trivial:

.encode()
.force_encoding()

For reading in a file via File.readlines(), this is also
simple because of stuff like:

File.readlines('test.txt', :encoding => 'ascii-8bit')

For Array and Hashes, however, this is a bit annoying for me.

I'd love to have an .encode method as well.

This method should try to convert all elements on an Array
or a Hash to another encoding IF they are a string object.

I'd like to be able to treat Array and Hashes in the same
way, so that I can e. g. convert a hash dictionary from
one encoding to the other quickly.

It already is possible of course, with some extra lines
of code, but I'd love to have a way to do so with just
one method call.

:

History

#1

Updated by naruse (Yui NARUSE) over 1 year ago

  • Target version deleted (2.2.0)

Also available in: Atom PDF