From: Matthew Kerwin Date: 2013-03-12T15:39:56+09:00 Subject: Re: Confusion with empty block printing --bcaec554d434aa002604d7b48ec3 Content-Type: text/plain; charset=ISO-8859-1 Stop using irb. Write a .rb file and run it. Then you will (hopefully) see that: 1. print needs a "\n" to push output to the next line print 'h' print 'i' print "p\ncat" 2. anything that starts with"#=>" isn't _real_ output; it's stuff irb does x = 3 # no output 2b) those things are the _VALUE OF THE PREVIOUS EXPRESSION_ puts '#=> ' + x.inspect 3. `print` has a _value_ of nil x = print('') # x is now nil puts '#=> ' + x.inspect # see? 3b) `foo.class` has a value of the object that foo is a new one of foo = Object.new foo2 = foo.class.new 4. these are the same: print {} print do end 4b) print {} outputs nothing, and still has a value of nil 4c) nil.class has a value of NilClass Sent from my phone, so excuse the typos. --bcaec554d434aa002604d7b48ec3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Stop using irb. Write a .rb file and run it. Then you will (hopefully) s= ee that:

1. print needs a "\n" to push output to the next line

=A0=A0=A0 print 'h'
=A0=A0=A0 print 'i'
=A0=A0=A0 print "p\ncat"

2. anything that starts with"#=3D>" isn't _real_ output= ; it's stuff irb does

=A0=A0=A0 x =3D 3=A0 # no output

2b) those things are the _VALUE OF THE PREVIOUS EXPRESSION_

=A0=A0=A0 puts '#=3D> ' + x.inspect

3. `print` has a _value_ of nil

=A0=A0=A0 x =3D print('')=A0 # x is now nil
=A0=A0=A0 puts '#=3D> ' + x.inspect=A0 # see?

3b) `foo.class` has a value of the object that foo is a new one of

=A0=A0=A0 foo =3D Object.new
=A0=A0=A0 foo2 =3D foo.class.new

4. these are the same:

=A0=A0=A0 print {}
=A0=A0=A0
=A0=A0=A0 print do
=A0=A0=A0 end

4b) print {}=A0 outputs nothing, and still has a value of nil
4c) nil.class has a value of NilClass

Sent from my phone, so excuse the typos.

--bcaec554d434aa002604d7b48ec3--