Obj.inspect (consoli)



  • How ruby make a similar conclusion to obj.inspect in the console for this object:

    ruby -e "p 'hello world!'"
    

    Or obj.inspect Not for console?



  • ♪ http://ruby-doc.org/core-2.3.1/Kernel.html#method-i-p It says clearly:

    For each object, directly writes obj.inspect followed by a newline to the program’s standard output.


    For each object, obj.inspect and following the transfer of the line to the standard conclusion.

    http://ruby-doc.org/core-2.3.1/Object.html#method-i-inspect I'm not in the process of concluding:

    Returns a string containing a human-readable representation of obj


    Returns the line containing a man-made performance obj

    ♪ ♪ Oh. String inherited from Object http://ruby-doc.org/core-2.3.1/String.html#method-i-inspect :

    Returns a printable version of str, surrounded by quote marks, with special characters escaped.


    Returns a suitable version str, circumferential and screened specials.

    ...then getting a literal of a given line suitable for the Ruby code. If you look at the contents of the line removed by puts:

    • reference line hello world
    • line.inspect contained "hello world"
    • line.inspect.inspect contained "\"hello world\""since the inspected line had double quotes, they were screened in that form

    See the pattern?


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2