Unexpected Keyword_End, Expecting $End (Syntaxerror)

unexpected keyword_end, expecting $end (SyntaxError)

This means there is a syntax error and translates to "the end keyword was found when nothing more was expected to complete the program". This is usually due to an unbalanced number of "openers". For instance,

foo.rb: (demonstration)

if true
puts "hello world"
end # the indent
end # is a lie

Line 4: syntax error, unexpected kEND [keyword_end], expecting $end

Happy coding.

ruby syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)

The do in line 132 is not supposed to be there. There are many other syntax errors in the code.

Ruby syntax error: unexpected keyword_end, expecting end-of-input

I think you are using case when what you really want is just plain ole if/else

You should only use case if you have one thing that you are testing which of several possibilities it is eg:

case my_string
when /blue/
do blue stuff
when /yellow/
do yellow stuff
when /red/
do red stuff
else
do something else
end

You should not use it to test multiple things eg what you are doing here:

case # nothing here to compare against the `when` cases
when type.match(/snapshot$/i) # here you are comparing type
when version.match(/latest$/i) # and now version
when type.match(/release$/i) # and now type again

also... you've got weird nesting that will not work. You code technically does this:

case # open the case statement
when type.match(/snapshot$/i) # first match
when version.match(/latest$/i) # second match
else # this counts as the else clause of the first case
end # this has now closed the case statement completely
# and now there's another when... without a case... which is why yuour code is borking
when type.match(/release$/i) # and now type again

What I think you're really trying to do is nest a second case statement inside the first one (if I'm wrong, correct me on this)>
If so... you really, really, really don't need case statements. Just use if/else like this

if type.match(/snapshot$/i) # first match
if version.match(/latest$/i) # second match
else # this counts as the else clause of the second if-statement
end # this has now closed the second if-statement
elsif type.match(/release$/i) # and now we test a second option against type
end # and this closes the first if-statement

if you realy, really must use case statements, then you need to do a few things:
a) actually specify what you're testign in the case-statement - right after the word case
b) repeat the keyword case every time you are opening a new, nested set of them... eg:

case type
when /snapshot$/i # first case - first option (testing type)
case version
when /latest$/i # second case - first option (testing version)
else # else clause of second case
end # end of second case
when /release$/i # first case - second option (testing type)
end # end of first case

Note that the case-statement is absolutely overkill when there is only one thing to test against (eg the second case statement).

unexpected keyword_end, expecting end-of-input

The lines w/ do in them should not have the .

@current_department.employees.each.do |c|

should be

@current_department.employees.each do |c|

do is the keyword for beginning a block, not a method on each

Getting syntax error, unexpected keyword_end, expecting end-of-input

Your indentation is messed up and you've added an extra end in there because of it.

The private declaration should be at the same level as class.

A general template looks like:

class Example
def method
# ...
end

private
def private_method
end
end

What you have:

class Example
def method
# ...
end

private
def private_method
end
end
end

syntax error, unexpected '}', expecting keyword_end }

There's some slightly unsual syntax in play here, with a single colon (:) at the end of the new call. E.g.

chrome = Watir::Browser.new:chrome

This is probably confusing the hash parser, which can use colons as a key/value separater, since ruby 1.9. E.g.

hash = {foo: 'bar'}

You can always force a piece of code to be evaluated regardless of it's surroundings, however, by wrapping it in brackets. You'll probably find this code works:

browser_conf = {
"chrome" => (Watir::Browser.new:chrome),
"firefox" => (Watir::Browser.new:firefox),
"ie" => (Watir::Browser.new:ie)
}

Update: I've just checked the Watir docs, and I believe you're calling new incorrecly. The symbol for the browser is an argument to new. So should either be after a space, or in brackets. Without either white space or brackets, it's not always able to parse that as an argument.

Here's the correct code:

browser_conf = {
"chrome" => Watir::Browser.new(:chrome),
"firefox" => Watir::Browser.new(:firefox),
"ie" => Watir::Browser.new(:ie)
}

Rspec returns syntax error of unexpected '{', expecting keyword_end

In Ruby 2.4.1 not having parens in the let was allowed but in Ruby 2.5.1 it is not.

So the fix is to add parens to the let, e.g.

change

let :source {'cba321'}

to

let (:source) {'cba321'}

Ruby Beginner- unexpected end-of-input, expecting keyword_end

You need one more end:

puts "Welcome to Shapes"
print "How big do you want your shape? "
shape_size = gets
shape_size = shape_size.chomp
print "Outside letter: "
outside_letter = gets
outside_letter = outside_letter.chomp
print " Inside Letter: "
inside_letter = gets
inside_letter = inside_letter.chomp
puts "About to draw a shape #{shape_size} big"
puts "using #{outside_letter} for the edge"
puts "and #{inside_letter} for the inside"
width = shape_size
height=shape_size
1.upto(height) do |row|
if row==1
puts outside_letter * width
elsif row==height
puts outside_letter * width
else
middle= inside_letter * (width-2)
puts
"#{outside_letter}#{middle}#{outside_letter}"
end
end # <--- here

Since you are learning here, I felt compelled to add more detail:

When you have a block, such as the 1.upto(height) do |row| in your code, that will always require an end, as it is a block (think of it like a unit of code). Within that block, you are executing the code for each item within the enumerable (ex. array). In this case, your enumerable is an array of each whole number between 1 and the value of height:

2.3.0 :005 > 1.upto(4) do |number|
2.3.0 :006 > puts "The number is: #{number}"
2.3.0 :007?> end
The number is: 1
The number is: 2
The number is: 3
The number is: 4


Related Topics



Leave a reply



Submit