This works on one machine with Ruby but not another.
Code:
describe 'testing reverse string different ways' do
let :thing {'cba321'}
it 'the system method' do
source = '123abc'
result = source.reverse
expect(result).to eq 'cba321'
end
end
Error:
SyntaxError:
/home/michael/Dropbox/90_2019/work/code/ruby__rails/ruby/reverse_string_tests_timing/test_spec.rb:12: syntax error, une
xpected '{', expecting keyword_end
let :thing {'cba321'}
^
/home/michael/Dropbox/90_2019/work/code/ruby__rails/ruby/reverse_string_tests_timing/test_spec.rb:12: syntax error, une
xpected '}', expecting end-of-input
let :thing {'cba321'}
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'}
Does any one know why
saved ? redirect '/success' : erb :signup
Throws the following error:
syntax error, unexpected ':', expecting keyword_end
While this does not?
saved ? redirect('/success') : erb(:signup)
I'm writing an extension for Redcarpet for a Jekyll-powered website. I want to use {x|y} as a tag in markdown that evaluates to the HTML <ruby> tag (and its associates). I wrote this class as per Jekyll's guide, Redcarpet's guide, and this guide on how to do so:
class Jekyll::Converters::Markdown::HotelDown < Redcarpet::Render::HTML
def preprocess(doc)
s = "<ruby><rb>\\1</rb><rp>(</rp><rt>\\2</rt><rp>)</rp></ruby>"
doc.gsub!(/\[([\s\S]+)\|([\s\S]+)\]/, s)
doc
end
end
But, I seem to be getting a couple errors when I run bundle exec jekyll serve:
Configuration file: C:/Users/Alex/OneDrive/codes/hotelc.me/hotelc.me/_config.yml
plugin_manager.rb:58:in `require': HotelDown.rb:4: syntax error, unexpected tIDENTIFIER, expecting ')' (SyntaxError)
doc.gs-ub!(/\[([\-s\S]+)\|([-\s\S]+)\]/-, s)
^
HotelDown.rb:4: syntax error, unexpected ')', expecting '='
doc.gs-ub!(/\[([\-s\S]+)\|([-\s\S]+)\]/-, s)
^
It seems there's something wrong with my syntax (an extra space, missing parentheses, or something like that). Is there something I've missed?
Your code has some special characters which is causing this error:
syntax error, unexpected ')', expecting '='
doc.gs-ub!(/\[([\-s\S]+)\|([-\s\S]+)\]/-, s)
Replace your current code with this piece of code:
class Jekyll::Converters::Markdown::HotelDown < Redcarpet::Render::HTML
#Overriding the preprocess() function
def preprocess(doc)
s = "<ruby><rb>\\1</rb><rp>(</rp><rt>\\2</rt><rp>)</rp></ruby>"
doc.gsub!(/\[([\s\S]+)\|([\s\S]+)\]/, s)
doc
end
end
markdown = Redcarpet::Markdown.new(HotelDown)
and it should work!
This is probably one line answer fot Ruby pros. I am getting syntax error:
unexpected tLBRACE at line 1
I believe this is closely related to the issue in described here but I am not able to figure whats wrong in my case.
Could some please pin point whats the issue ?
Thank you for your time.
def user_profile_picture(user, size: [50, 50], type: :square, style: 'img-polaroid', opts: {})
tag :img,
{ width: ("#{size[0]}px" if size),
height: ("#{size[1]}px" if size),
src: facebook_profile_picture(user, type),
alt: '',
class: [('verified' if user.class == User.model_name && user.facebook_verified?), style].compact.join(' ')
}.merge(opts)
end
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.0]
****Stack trace****
SyntaxError - /Developer/rails-workspace/roommate/app/helpers/users_helper.rb:7: syntax error, unexpected tLABEL
...er_profile_picture(user, size: [50, 50], type: :square, sty...
... ^
/Developer/rails-workspace/roommate/app/helpers/users_helper.rb:7: syntax error, unexpected ',', expecting keyword_end
..._picture(user, size: [50, 50], type: :square, style: 'img-p...
... ^
/Developer/rails-workspace/roommate/app/helpers/users_helper.rb:7: syntax error, unexpected ',', expecting keyword_end
...:square, style: 'img-polaroid', opts: {})
... ^
/Developer/rails-workspace/roommate/app/helpers/users_helper.rb:10: syntax error, unexpected ',', expecting keyword_end
/Developer/rails-workspace/roommate/app/helpers/users_helper.rb:11: syntax error, unexpected ',', expecting keyword_end
/Developer/rails-workspace/roommate/app/helpers/users_helper.rb:12: syntax error, unexpected ',', expecting keyword_end
/Developer/rails-workspace/roommate/app/helpers/users_helper.rb:15: syntax error, unexpected '}', expecting keyword_end
}.merge(opts)
^
/Developer/rails-workspace/roommate/app/helpers/users_helper.rb:127: syntax error, unexpected keyword_end, expecting $end:
app/helpers/users_helper.rb:7:in `'
(gem) activesupport-3.2.9/lib/active_support/dependencies.rb:469:in `block in load_file'
(gem) activesupport-3.2.9/lib/active_support/dependencies.rb:639:in `new_constants_in'
(gem) activesupport-3.2.9/lib/active_support/dependencies.rb:468:in `load_file'
My bet is that you're using a earlier Ruby version than 2.0.
At the first line, you've defined the method with keyword arguments. The error you've obtained is typically the one when working with an earlier Ruby version such as 1.9. The hash syntax 'size:' It's an unexpected syntax in a list of parameter in those versions.
In Ruby 1.9, you should define the method as following:
def user_profile_picture(user, size=[50, 50], type=:square, style='img-polaroid', opts={})
#...
end
I am trying to deploy a rails 3.2 app where the ruby version is 1.8. I could workaround a few hash syntax troubles I had, but there is still one I can't get over with:
Note I hired a hosting service that won't install ruby 1.9.
The error is
from {app_path}/config/environment.rb:5
[ pid=586526 thr=203092280 file=utils.rb:176 time=2012-05-04 15:32:29.667 ]: *** Exception SyntaxError in PhusionPassenger::Rack::ApplicationSpawner ({app_path}/config/initializers/wrap_parameters.rb:8: syntax error, unexpected tASSOC, expecting '}'
{app_path}/config/initializers/wrap_parameters.rb:8: warning: don't put space before argument parentheses
{app_path}/config/initializers/wrap_parameters.rb:8: warning: don't put space before argument parentheses
from {app_path}/config/environment.rb:5
[ pid=539635 thr=202883380 file=utils.rb:176 time=2012-05-04 14:30:21.570 ]: *** Exception SyntaxError in PhusionPassenger::Rack::ApplicationSpawner ({app_path}/config/initializers/wrap_parameters.rb:8: syntax error, unexpected ':', expecting kEND
from {app_path}/config/environment.rb:5
[ pid=539635 thr=202883380 file=utils.rb:176 time=2012-05-04 14:29:31.744 ]: *** Exception SyntaxError in PhusionPassenger::Rack::ApplicationSpawner ({app_path}/config/initializers/wrap_parameters.rb:8: syntax error, unexpected ':', expecting kEND
The file is config/initializers/wrap_parameters.rb and the content is like follows:
ActiveSupport.on_load(:action_controller) do
# it was originally
# wrap_parameters format: [:json] # ruby 1.9 syntax
# the follow line is line 8
wrap_parameters :format => [:json] # ruby 1.8 syntax
# i already tried
# wrap_parameters {:format => [:json]}
# wrap_parameters({:format => [:json]})
# wrap_parameters(:format => [:json])
end
# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end
Here is config/enviroment.rb
#config/environment.rb
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Flog::Application.initialize!
I am a few hours trying to get rid of this issue.
Thank you in advace