0

I am writing some code as a solution for a programming problem. I have just introduced a new function into my solution which is causing the following errors. Note that the errors are not there without this function.

search.rb:48: syntax error, unexpected keyword_end
search.rb:68: syntax error, unexpected $end, expecting keyword_end

I realize that this is caused by a mispaced end. I just can't find it. (I have marked the location of the first error with a comment. The second error is the last line of code and not shown here.)

def processing_function
    qcount = pcount = $n
    qstrength = 0
    $query_hash.each do |qkey, qvalue|
        print "Q",qkey,": "
        $page_hash.each do |pkey, pvalue|
            qvalue.each_index do |i|
                pvalue.each_index do |j|
                    if qvalue[i]==pvalue[j]
                        qstrength = qstrength + qcount*pcount
                    end
                    pcount--
                end #** This is line 48. First error occurs here. **#
                qcount--
                pcount=$n
            end
            if qstrength!=0
                print "P",pkey," "
            end
            qstrength=0
        end
        print "\n"
    end
end
7
  • 1
    You should learn ruby syntax. For example, you can't use val-- code. Commented Mar 29, 2013 at 8:01
  • @YevgeniyAnfilofyev I just started learning yesterday and I am coming from C & C++. Thank you for pointing it out. I updated the code. Commented Mar 29, 2013 at 8:05
  • That's ok. So updated code still has an errors? Commented Mar 29, 2013 at 8:08
  • 2
    Please don't edit your question in a way that fundamentally changes the original question, e.g. by removing a syntax error which was the original source of your issue. Commented Mar 29, 2013 at 8:28
  • 1
    Take the time to read the Ruby Style Guide. While it's not an official style guide, it has a lot of good tips. In your code, put spaces around your operators and use two spaces to indent. Also, you're using $globals, which cause code smell. Odds are really good you don't need them if you write your code correctly. $query_hash, $page_hash and $n should probably be parameters instead of globals. Commented Mar 29, 2013 at 8:38

1 Answer 1

4

Ruby doesn't have -- or ++ operator. Use, for example += 1 instead.

There is short article about differences for C/C++ and Ruby.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.