title: Ruby: calling a defined function
body: <p>I have a ruby code that supposes to read a paragraph and find the total number of characters, words, and sentences then find the ARI (Automated Readability Index) and decide which grade level. It's my first time using ruby and i'm not sure how to call the function</p>
  <p>is this correct to write it after the last end</p>
  <pre><code>calcARI(&quot;paragraph.txt&quot;)
  </code></pre>
  <p>paragraph.txt is the name of the file</p>
  <p>this is the code</p>
  <pre><code>    def calcARI(paragraph)
  
        file = File.open(&quot;paragraph.txt&quot;,&quot;r&quot;)
  
        if file
  
          file_data = file.read
  
          file.close
  
          charCount=0
  
          wordCount=0
  
          sentenceCount=0
  
          ARIvalue==0
  
          gradeLevel=&quot;&quot;
  
          file.each_line { |line|
  
              charCount+=line.size
  
              for i in 1..line.length
  
                  if(line[i]=='.')
  
                      sentenceCount+=1
  
                  end
  
                  if(line[i]==' ')
                          wordCount+=1
  
                  end
  
              end
  
              
  
          }
  
          ARIvalue==4.71*(charCount/wordCount)+0.5*(wordCount/sentenceCount)-21.43
  
          case ARIvalue
  
          when 1
  
              gradeLevel=&quot;5-6 Kindergarten&quot;
  
          when 2
  
              gradeLevel=&quot;6-7 First/Second Grade&quot;
  
          when 3
  
              gradeLevel=&quot;7-9 Third Grade&quot;
  
          when 4
  
              gradeLevel=&quot;9-10 Fourth Grade&quot;
  
          when 5
  
              gradeLevel=&quot;10-11Fifth Grade&quot;
  
          when 6
  
              gradeLevel=&quot;11-12 Sixth Grade&quot;
  
          when 7
  
              gradeLevel=&quot;12-13 Seventh Grade&quot;
  
          when 8
  
              gradeLevel= &quot;13-14 Eighth Grade&quot;
  
          when 9
  
              gradeLevel= &quot;14-15 Ninth Grade&quot;
  
          when 10
  
              gradeLevel= &quot;15-16 Tenth Grade&quot;
  
          when 11
  
              gradeLevel= &quot;16-17 Eleventh Grade&quot;
  
          when 12
  
              gradeLevel= &quot;17-18 Twelth Grade&quot;
  
          when 13
  
              gradeLevel= &quot;18-24 College student&quot;
  
          when 14
  
              gradeLevel=&quot;24+ Professor&quot;
  
          end        
  
          puts &quot;Total # of Charecter: #{charCount}&quot;
  
          puts &quot;Total # of words: #{wordCount}&quot;
  
          puts &quot;Total # of sentences: #{sentenceCount}&quot;
  
          puts &quot;Total # of Automated Readability Index: #{ARIvalue}&quot;
  
          puts &quot;Grade Level: '#{gradeLevel}''&quot;
  
      else
  
          puts &quot;Unable to open file!&quot;
  
      end
    end
  </code></pre>