dimanche 31 juillet 2016

Ruby: Using "if else" inside a function gives unexpected keyword_end error

I am very much new to Ruby. Experts, please bare with me.

I have defined a function which looks like this:

def putValAndmyBool val mybool
    if mybool
        puts val + "true"
    else
        puts val + "false"
    end
end

It gives the following error:

SyntaxError: (irb):101: syntax error, unexpected tIDENTIFIER, expecting ';' or '(irb):107: syntax error, unexpected keyword_end, expecting end-of-input from K:/Ruby22-x64/bin/irb:11:in `'

But when I defined following function, it runs successfully. The reason I tried doing this is I thought something in line puts val + "true" is causing the issue.

def addbool val
    puts val + "true"
end

Any explanation is appreciated. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire