Project

General

Profile

Feature #12275

Updated by asnow (Andrew Bolshov) almost 8 years ago

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 = true 
     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

Back