ruby - Why can't some methods be used by another method? -


Why can not the methods be changed by any other method? In particular, why does not this work?

  puts' Enter a number: 'first = gets.chomp puts' Enter the second number:' last = gets.chomp total = first. To_i + final. To_i ' 'Total of two values' + total.to_s  

These two variables are now integers why can not they be added? For example, I can do this, which is not different when thinking about it:

  total = first. Langt + seconds.langt  

In the last line of your code you are Returns is a total of 'two values' + total

total integer , but you try to concast on string , Then it also puts an error like below.

  1. 9.3p448: 013 & gt; Enters 'Enter a number:' Enter a number: = & gt; Zero 1.9.3p448: 014 & gt; First = gets.chomp 3 = & gt; "3" 1.9.3p448: 015> Enter 'Enter second number:' Enter second number: = & gt; Zero 1.9.3p448: 016 & gt; Final = gets.chomp3 = & gt; "3" 1.9.3p448: 017> 1. 9.3p448: 018 & gt; Total = first.O_I + last.ut_a = & gt; 6 1. 9.3p448: 023 & gt; Total number of total values ​​is' 'Total type error: FixName can not be converted to string (IRB): 23: in `+'  

Similar is the only The change is integer to string as total.to_s or is a total of two values: # {total} " We have to do this.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -