ivorykoder ivorykoder - 2 months ago 6
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.


This line is incorrect

def putValAndmyBool val mybool

I suppose should be

def putValAndmyBool val, mybool