--------------C555268C072C26894FC261C3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Why does the following prints 4.0 but prints 60.0 when the statement
in durationInMinutes s changed to
@duration value*60).to_i
or
self.duration value*60).to_i?
I thought it should print 60.0 in all three cases.
----------------------------------
class Song
attr_reader :name, :artist, :duration
attr_writer :duration, :artist
def initialize(name1, artist1, duration1)
@name ame1
@artist rtist1
@duration uration1
end
def to_s
"Song: #{@name}--#{@artist} (#{@duration})"
end
def durationInMinutes
duration/60.0
end
def durationInMinutes alue)
duration value*60).to_i
end
end
aSong ong.new("New Song", "New ArtistShadows", 240)
aSong.durationInMinutes 0.0
print aSong.durationInMinutes.to_s
--------------C555268C072C26894FC261C3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<tt>Why does the following prints 4.0 but prints 60.0 when the statement
in durationInMinutes s changed to</tt><tt></tt>
<p><tt>@duration value*60).to_i</tt>
<br><tt>or</tt>
<br><tt>self.duration value*60).to_i?</tt><tt></tt>
<p><tt>I thought it should print 60.0 in all three cases.</tt>
<br><tt></tt>
<br><tt></tt> <tt></tt>
<p><tt>----------------------------------</tt><tt></tt>
<p><tt>class Song</tt>
<br><tt> attr_reader :name, :artist, :duration</tt>
<br><tt> attr_writer :duration, :artist</tt>
<br><tt> </tt>
<br><tt> def initialize(name1, artist1, duration1)</tt>
<br><tt> @name ame1</tt>
<br><tt> @artist rtist1</tt>
<br><tt> @duration uration1</tt>
<br><tt> end</tt><tt></tt>
<p><tt> def to_s</tt>
<br><tt> "Song: #{@name}--#{@artist} (#{@duration})"</tt>
<br><tt> end</tt><tt></tt>
<p><tt> def durationInMinutes</tt>
<br><tt> duration/60.0</tt>
<br><tt> end</tt><tt></tt>
<p><tt> def durationInMinutes alue)</tt>
<br><tt> duration value*60).to_i</tt>
<br><tt> end</tt><tt></tt>
<p><tt>end</tt><tt></tt>
<p><tt>aSong ong.new("New Song", "New ArtistShadows", 240)</tt>
<br><tt>aSong.durationInMinutes 0.0</tt>
<br><tt>print aSong.durationInMinutes.to_s</tt></html>
--------------C555268C072C26894FC261C3--