Inspect

A

Amir Ebrahimifard

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
 
J

Jean-Julien Fleck

2010/7/22 Amir Ebrahimifard said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top