ivorykoder ivorykoder - 1 year ago 50
Ruby Question

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"
puts val + "false"

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"

Any explanation is appreciated. Thanks in advance.

Answer Source

This line is incorrect

def putValAndmyBool val mybool

I suppose should be

def putValAndmyBool val, mybool
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download