Inspect

Discussion in 'Ruby' started by Amir Ebrahimifard, Jul 22, 2010.

  1. Hi
    What is the use of "inspect"?
    for example in this code:

    array = [1,2,3,4,5]
    # => [1, 2, 3, 4, 5]
    array2 = [1, "2", 3.0, ["a", "b"], "dog"]
    # => [1, "2", 3.0, ["a", "b"], "dog"]
    array.inspect
    # => "[1, 2, 3, 4, 5]"
    array
    # => [1, 2, 3, 4, 5]
    puts array
    # 1
    # 2
    # 3
    # 4
    # 5
    # => nil
    puts array.inspect
    # [1, 2, 3, 4, 5]
    # => nil
    puts array2.inspect
    # [1, "2", 3.0, ["a", "b"], "dog"]
    # => nil
    --
    Posted via http://www.ruby-forum.com/.
     
    Amir Ebrahimifard, Jul 22, 2010
    #1
    1. Advertising

  2. 2010/7/22 Amir Ebrahimifard <>:
    > Hi
    > What is the use of "inspect"?


    ~> ri Object.inspect
    --------------------------------------------------------- Object#inspect
    obj.inspect =3D> string
    ------------------------------------------------------------------------
    Returns a string containing a human-readable representation of
    _obj_. If not overridden, uses the +to_s+ method to generate the
    string.

    [ 1, 2, 3..4, 'five' ].inspect #=3D> "[1, 2, 3..4, \"five\"]"
    Time.new.inspect #=3D> "Wed Apr 09 08:54:39 CDT 200=
    3"

    Cheers,

    --=20
    JJ Fleck
    PCSI1 Lyc=E9e Kl=E9ber
     
    Jean-Julien Fleck, Jul 22, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QnJpYW4gS2l0dA==?=

    How do you inspect HTML controls in compiled C#?

    =?Utf-8?B?QnJpYW4gS2l0dA==?=, May 22, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    516
    Kevin Spencer
    May 30, 2005
  2. John C.

    inspect aspx form with reflection?

    John C., Dec 5, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    413
    John C.
    Dec 5, 2005
  3. Replies:
    4
    Views:
    4,788
    wpghost
    May 8, 2006
  4. Ian Lazarus

    inspect for throws

    Ian Lazarus, Nov 9, 2003, in forum: C++
    Replies:
    1
    Views:
    280
  5. deluxstar
    Replies:
    5
    Views:
    867
    Terry Reedy
    Sep 25, 2010
Loading...

Share This Page