ivorykoder
ivorykoder

Reputation: 1020

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

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

Upvotes: 0

Views: 101

Answers (1)

Ursus
Ursus

Reputation: 30071

This line is incorrect

def putValAndmyBool val mybool

I suppose should be

def putValAndmyBool val, mybool

Upvotes: 1

Related Questions