Issue #12275 has been updated by tad (Tadashi Saito).


Thank you for your comments.

> I think rather than using true/false to distinguish single and double quotes, it would be better to have a keyword parameter, such as quotes: :single (and quotes: :double, but that would be default).

I think we can forget about arguments (i.e. additional quotes), because current implementation never uses `eval()` internally.

My `String#undump` takes no argument just like: 

~~~ruby
'"\u00FC"'.undump #=> ""
~~~

I'll write detailed specs when I submit a patch.  Basically I focused to does inverse of `String#dump`.

> Also, please think about encodings. Some people may want all non-ASCII characters escaped, but others may not want that at all.

Unfortunately, I couldn't understand your concern.  I think we're discussing about unescaping/undumping, not escaping.
Note that `String#dump` already escapes all of non-ASCII characters, so I'm trying to unescape them all with `undump`.

----------------------------------------
Feature #12275: String unescape
https://bugs.ruby-lang.org/issues/12275#change-67913

* Author: asnow (Andrew Bolshov)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I think it will be usefull to have function that convert input string as it was written in prime qouted string or in double qouted string. It's part of metaprogramming.
Example:

~~~ ruby
class String
  # Create new string like it will be writed in qoutes. Optional argument define type of qouting used: true - prime qoute, false - double qoute. Default is double qoute.
  def unescape prime = false
    eval( prime ? "'#{self}'" : "\"#{self}\"" )
  end
end

"\\\t".unescape # => "\t"
~~~

Other requests:
http://www.rubydoc.info/github/ronin-ruby/ronin-support/String:unescape
http://stackoverflow.com/questions/4265928/how-do-i-unescape-c-style-escape-sequences-from-ruby
http://stackoverflow.com/questions/8639642/best-way-to-escape-and-unescape-strings-in-ruby

Realized
http://www.rubydoc.info/github/ronin-ruby/ronin-support/String:unescape



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>