Direct string representation in Ruby -


Is there an easy way to present a direct string of ruby ​​build?

For example:

  a = [: foo,: bar]   

when a.to_s I: <<> "foobar"

What I'm looking for:

  "[ : Foo ,: bar] "   

Which version of Ruby are you using ? I'm getting the use of Ruby 1.9:

  irb (main): 002: 0> A = [: foo ,: bar] = & gt; [: Foo,: bar] irb (main): 003: 0> A.to_s = & gt; "[: Foo,: Bar]" IRB (Main): 004: 0> A.inspect = & gt; "[: Foo,: bar]"   

Edit: As indicated by @ Flanders, in 1.8.7, you inspect Can . In general, inspection is considered to provide human-readable strings, even if to_s does not:

obj.inspect  ???? String

returns the human-readable representation string of obj if it is not overridden and there is no frequency variable, then uses the to_s method to generate the string.

There is no claim about being human-readable.

Comments