Unexpected keyword_end error, yet syntax seems fine
Your error comes from line:
current_word ++
There's no such syntax in Ruby. It should be:
current_word += 1
What's more, you create your regexp incorrectly. It should be:
namecatcher_regex = /^[\.{1}]([A-Z]+)\.{3}/
There may be some other errors that I didn't notice.
Why am I getting unexpected keyword_end error with this block?
I was an idiot, I totally forgot that Ruby doesn't make use of the increment operator....doh!
Changed from:
@followers2.each do |follow|
@followers3 << Twitter.user(follow)
break if i >10
i++
end
To this:
@followers2.each do |follow|
@followers3 << Twitter.user(follow)
break if i >10
i+=1
end
Syntax error, unexpected keyword_end and unexpected end_of_input
++
operator doesn't exist in Ruby. Just use += 1
.
Syntax error, unexpected keyword_end, expecting ')' end
I think I see your syntax error on this line:<p><%= number_to_currency(@pacs_money + " from " + @pacs + " PACs" %></p>
There's no closing parenthesis for number_to_currency
. It should be:
<p><%= number_to_currency(@pacs_money) + " from " + @pacs + " PACs" %></p>
Syntax Error in Ruby. unexpected keyword_end, expecting end-of-inputs
You can't define a module using module Auth()
:
irb(main):001:0> module Auth()
irb(main):002:1> end
SyntaxError: (irb):1: syntax error, unexpected '\n', expecting :: or '[' or '.'
and
irb(main):001:0> module Auth()
irb(main):002:1> def login(id)
irb(main):003:2> end
irb(main):004:1> end
SyntaxError: (irb):1: syntax error, unexpected '\n', expecting :: or '[' or '.'
(irb):4: syntax error, unexpected keyword_end, expecting end-of-input
Removing the trailing parenthesis fixes the error:
irb(main):001:0> module Auth
irb(main):002:1> def login(id)
irb(main):003:2> end
irb(main):004:1> end
=> :login
and
irb(main):001:0> module Auth
irb(main):002:1> module_function()
irb(main):003:1>
irb(main):004:1* def login(id)
irb(main):005:2> members = ['abc', 'def', 'ghi']
irb(main):006:2>
irb(main):007:2* for member in members do
irb(main):008:3* if (id == member)
irb(main):009:4> return true
irb(main):010:4> end
irb(main):011:3> end
irb(main):012:2> return false
irb(main):013:2> end
irb(main):014:1> end
=> :login
Your code could be more Ruby-like:
def login(id)
['abc', 'def', 'ghi'].each do |member|
return true if (id == member)
end
return false
end
login('ghi') # => true
login('foo') # => false
which can be refactored to:
def login(id)
['abc', 'def', 'ghi'].any? { |member| (id == member) }
end
login('ghi') # => true
login('foo') # => false
then to:
def login(id)
['abc', 'def', 'ghi'].include?(id)
end
login('ghi') # => true
login('foo') # => false
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
Related Topics
Converting Camel Case to Underscore Case in Ruby
Nokogiri Installation Fails -Libxml2 Is Missing
Issue Updating Ruby on MAC With Xcode 4.3.1
What's Different Between Each and Collect Method in Ruby
How to Force Rails_Env in a Rake Task
Regular Expressions With Validations in Ror 4
Weird Backslash Substitution in Ruby
What Does the "Map" Method Do in Ruby
Add a Default Value to a Column Through a Migration
How to Have Ruby Logger Log Output to Stdout as Well as File
How to Get the Current Absolute Url in Ruby on Rails
Difference Between Require_Relative and Require in Ruby
Printing the Source Code of a Ruby Block
Submit Post Data from Controller to Another Website in Rails