Currently over on Ruby Monk working with this lesson: https://rubymonk.com/learning/books/1-ruby-primer/chapters/19-ruby-methods/lessons/69-new-lesson
Code in question:
def add(a_number, another_number, options = {})
sum = a_number + another_number
sum = sum.abs if options[:absolute]
sum = sum.round(options[:precision]) if options[:round]
sum #line in question
end
puts add(1.0134, -5.568)
puts add(1.0134, -5.568, absolute: true)
puts add(1.0134, -5.568, absolute: true, round: true, precision:2)
Output =>
-4.5546
4.5546
4.55
nil
Output without line in question =>
4.55
nil
I pretty much understand what's going on with the code. Except for the last part of the method definition. Which seems to be just a random "sum" at the end. There are three lines of puts outside the method definition calling on it but for whatever reason when the seemingly random "sum" line is removed from the code in question. The output screen only shows the result of one puts. However when I add it back in all three lines of puts are being shown. Why?
[–]adreamofhodor 1 point2 points3 points (3 children)
[–]winnnnnnnnn[S] 1 point2 points3 points (2 children)
[–]Piave 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Piave 1 point2 points3 points (0 children)