Home > rails syntax > rails syntax error unexpected $end expecting kend

Rails Syntax Error Unexpected $end Expecting Kend

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Unexpected $end , expecting kEND up vote 0 down vote favorite My task is to make a more efficient binary search code using Ruby. I followed the logic from this link: http://www.cprogramming.com/discussionarticles/sorting_and_searching.html My code is as follows: def bsearch(a, k) lower = 0 upper = a.length-1 while a[upper].to_f> k.to_f and a[lower].to_f< k.to_f low_diff = k.to_f -a[lower].to_f range_diff = a[upper].to_f-a[lower].to_f count_diff = upper-lower range = low_diff/range_diff * count_diff + lower if k==a[lower] return lower if k.to_f > a[range].to_f lower = range+1 else if k.to_f < a[range].to_f upper =range else lower = range end end end I double check, but I do not know why I keep experiencing the followin error: unexpected $end , expecting kEND ruby syntax-error share|improve this question edited Sep 24 '13 at 7:37 toro2k 14.7k73451 asked Sep 24 '13 at 5:52 user2445971 2719 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote You lost an end in one of the if statement. And instead of else if, the keyword in Ruby is elsif if k==a[lower] return lower end #lost this end if k.to_f > a[range].to_f lower = range+1 elsif k.to_f < a[range].to_f #use elsif upper =range else lower = range end share|improve this answer answered Sep 24 '13 at 5:56 Yu Hao 84.4k18117177 Hi Yu Hao, my results yield nill when its suppose to return a location in the array, please help –user2445971 Sep 24 '13 at 6:11 @user2445971 That's a different question, as I only checked the compilation error when I posted the answer. It's better to ask a new question about it. –Yu Hao Sep 24 '13 at 6:16 add a comment| up vote 0 down vote You cannot write else if in ruby you should write elsif def bsearch(a, k) lower = 0 upper = a.length-1 while a[upper].to_f> k.to_f && a[lower

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Ruby unexpected kEND, expecting $end up vote 1 down vote favorite require 'open-uri' print "Enter a URL" add = gets open(#{add}) do |f| j = f.read.scan(/http://stackoverflow.com/questions/18973899/unexpected-end-expecting-kend me the error:findimages.rb:8: syntax error, unexpected kEND, expecting $end Why is this? ruby share|improve this question asked Apr 9 '12 at 19:04 Billjk 2,098123257 2 That error means "I was looking through your source code, and I expected to see the end of the file, but I found an end instead." –Phrogz Apr 9 '12 at 19:08 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote accepted #{} works only inside interpolated strings. Use open(add) (or perfectly correct, http://stackoverflow.com/questions/10078316/ruby-unexpected-kend-expecting-end but perfectly unnecessary open("#{add}")). share|improve this answer answered Apr 9 '12 at 19:06 Amadan 91.7k885133 add a comment| up vote 4 down vote On this line: open(#{add}) do |f| You are trying to use #{} to interpolate a variable into a string, but outside of a string. The # is being interpreted as the start of the comment, and the rest of the line is treated as a comment. You can just use add directly here, without any string interpolation. share|improve this answer answered Apr 9 '12 at 19:08 Brian Campbell 164k37260291 I do find it a little odd that the lexer was looking for $end instead of a right paren. –Phrogz Apr 9 '12 at 19:20 @Phrogz When I tested this out with a similar program, I got an error about the missing paren, and an error about $end. I am assuming that the first error gets the parser confused, and so the second error is spurious. –Brian Campbell Apr 9 '12 at 23:20 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged ruby or ask your own question. asked 4 years ago viewed 5563 times active 4 years

years ago by Hoormazd Kia Hoormazd Kia Pro Student 6,075 Points syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError) rails syntax Hello, My problem begins about 5 minutes into the tutorial video, where we are asked to run the following command in our CLI "bin/rspec spec/features/todo_lists/edit_spec.rb " We are supposed rails syntax error to expect a failure, but I receive a "expecting keyword_end" syntax error as mentioned above, but the error isn't coming from the edit_spec.rb file, it's coming from all over the place, here's the full text... ** Myname-MacBook-Pro:odot username$ bin/rspec spec/features/todo_lists/edit_spec.rb /Users/username/treehouse/projects/odot/config/environment.rb:2:in require': /Users/username/treehouse/projects/odot/config/application.rb:28: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError) from /Users/username/treehouse/projects/odot/config/environment.rb:2:in' from /Users/username/treehouse/projects/odot/spec/spec_helper.rb:3:in require' from /Users/username/treehouse/projects/odot/spec/spec_helper.rb:3:in' from /Users/username/treehouse/projects/odot/spec/features/todo_lists/edit_spec.rb:1:in require' from /Users/username/treehouse/projects/odot/spec/features/todo_lists/edit_spec.rb:1:in' from /Users/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in load' from /Users/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:inblock in load_spec_files' from /Users/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:in each' from /Users/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/configuration.rb:1065:inload_spec_files' from /Users/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/command_line.rb:18:in run' from /Users/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/core/runner.rb:103:inrun' from /Users/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-2.99.1/lib/rspec/co

unexpected end-of-input, expecting keyword_end In the Ruby foundation example video one of the examples involves building a speech class , but everytime I run the program i get the following error - "syntax error, unexpected end-of-input, expecting keyword_end" here's my speech-example.rb code. class Speech def initialize print "What is the speech name? " @title = gets.chomp @lines = [] while add_line puts "Line added." end end def title @title end def add_line puts "Add a line: (blank line to exit)" line = gets.chomp if line.length > 0 @lines.push line return line else return nil end def each(&block) @lines.each { |line| yield line} end end speech = Speech.new speec.each do |line| puts "[#{speech.title}] @{line}" end Oh, I'm also running the following version of Ruby - ruby 2.1.2p95 Thanks guys 2 Answers MOD Michael Hulet Treehouse Moderator 34,791 Points Michael Hulet Michael Hulet Treehouse Moderator 34,791 Points over 2 years ago You're missing and end to close out your add_line method. This code works: class Speech def initialize print "What is the speech name? " @title = gets.chomp @lines = [] while add_line puts "Line added." end end def title @title end def add_line puts "Add a line: (blank line to exit)" line = gets.chomp if line.length > 0 @lines.push line return line else return nil end #You were missing the end statement right here end def each(&block) @lines.each { |line| yield line} end end speech = Speech.new speec.each do |line| puts "[#{speech.title}] @{line}" end PRO Hoormazd Kia Pro Student 6,075 Points Hoormazd Kia Hoormazd Kia Pro Student 6,075 Points over 2 years ago Thanks. guess I was just tired :) Posting to the forum is only allowed for members with active accounts. Please sign in or sign up to post. Our mission is to bring affordable, technology education to people everywhere, in order to help them achieve their dreams and change the world. Our Company About Us Contact Us Community Treehouse Stories Student Perks Treehouse Blog Affiliate Program Careers Topics HTML CSS Design JavaScript Ruby PHP WordPress iOS Android Development Tools Business Tra

 

Related content

rails syntax error unexpected kend expecting $end

Rails Syntax Error Unexpected Kend Expecting end p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow relatedl the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Ruby unexpected kEND expecting

rails syntax error unexpected kend

Rails Syntax Error Unexpected Kend p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss relatedl the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up About Ruby error 'kEnd' up vote

rails syntax error unexpected tassoc expecting kend

Rails Syntax Error Unexpected Tassoc Expecting Kend p here for a quick overview of the site Help Center Detailed answers to any questions relatedl you might have Meta Discuss the workings and policies ruby tassoc of this site About Us Learn more about Stack Overflow the company ruby hash Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up

rails syntax error reserved word function

Rails Syntax Error Reserved Word Function table id toc tbody tr td div id toctitle Contents div ul li a href Coffee Script a li li a href Coffeescript Vs Javascript a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you relatedl might have Meta Discuss the workings and policies of this convert js to coffee site About Us Learn more about Stack Overflow the company Business Learn javascript in rails more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags

rails syntax error unexpected tassoc

Rails Syntax Error Unexpected Tassoc p here for a quick overview of the site Help relatedl Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Syntax error unexpected tASSOC expecting keyword