unexpected tLBRACE - ruby

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

Related

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

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'}

syntax error, unexpected ')', expecting '='

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.gs­ub!(/\[([\­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!

Foundation 5 Project Installation Fails

I've followed the steps on the Getting Started with SASS page to install Foundation 5 and the required components.
I am now trying to install Foundation into a project folder, via Terminal (i.e. Foundation new myProject).
Terminal returns a long list of errors that I've pasted in below.
No idea what this issue could be -- any ideas are greatly appreciated.
List of directories inRuby/Gems/1.8/gems/:
chunky_png-1.3.3
compass-1.0.1
compass-core-1.0.1
compass-import-once-1.0.5
ffi-1.9.6
foundation-1.0.4
multi_json-1.10.1
rb-fsevent-0.9.4
rb-inotofy-0.9.5
sass-3.4.9
thor-0.19.1
zurb-foundation-4.3.2
The errors:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': /Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:44: syntax error, unexpected ':', expecting ')' (SyntaxError)
run("gem install compass", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:44: Can't assign to true
run("gem install compass", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:44: syntax error, unexpected ':', expecting '='
run("gem install compass", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:45: syntax error, unexpected ':', expecting ')'
... run("rbenv rehash", capture: true, verbose: false) if whic...
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:45: Can't assign to true
..."rbenv rehash", capture: true, verbose: false) if which("rbe...
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:45: syntax error, unexpected ':', expecting '='
...hash", capture: true, verbose: false) if which("rbenv")
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:94: syntax error, unexpected ':', expecting ')'
run("compass compile", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:94: Can't assign to true
run("compass compile", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:94: syntax error, unexpected ':', expecting '='
run("compass compile", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:97: syntax error, unexpected ':', expecting ')'
run("compass compile", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:97: Can't assign to true
run("compass compile", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:97: syntax error, unexpected ':', expecting '='
run("compass compile", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:114: syntax error, unexpected ':', expecting kEND
option :libsass, type: :boolean, default: false
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:115: syntax error, unexpected ':', expecting kEND
option :version, type: :string
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:127: syntax error, unexpected ':', expecting ')'
...one #{repo} #{name}", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:127: Can't assign to true
...repo} #{name}", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:127: syntax error, unexpected ':', expecting '='
...ame}", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:130: syntax error, unexpected ':', expecting ')'
run("bower install", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:130: Can't assign to true
run("bower install", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:130: syntax error, unexpected ':', expecting '='
run("bower install", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:132: syntax error, unexpected ':', expecting ')'
run("git remote rm origin", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:132: Can't assign to true
run("git remote rm origin", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:132: syntax error, unexpected ':', expecting '='
run("git remote rm origin", capture: true, verbose: false)
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:149: syntax error, unexpected ':', expecting kEND
option :version, type: :string
^
/Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli/generator.rb:159: syntax error, unexpected $end, expecting kEND
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/foundation-1.0.4/lib/foundation/cli.rb:2
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/foundation-1.0.4/bin/foundation:3
from /usr/bin/foundation:19:in `load'
from /usr/bin/foundation:19
The obvious reason that I was overlooking is the Ruby version. The Foundation docs state Ruby 1.9+ is required, and I had only Ruby 1.8 (running OS X 10.8.5).

Syntax error, unexpected ':', expecting ')'

I'm running into this syntax error with the below code and I can't figure out why ruby is complaining about it.
def user_list
server = Lumberg::Whm::Server.new(
host: "localhost",
hash: IO.read("/root/.accesshash")
)
results = server.account.list
accounts = result[:params][:acct].map {|a| a["user"] }
end
end
Syntax error is as follows:
# bundle exec bin/userscan
bin/userscan:3:in `require': /usr/src/userscan/lib/userscan.rb:131: syntax error, unexpected ':', expecting ')' (SyntaxError)
host: "localhost",
^
/usr/src/userscan/lib/userscan.rb:131: syntax error, unexpected ',', expecting kEND
/usr/src/userscan/lib/userscan.rb:133: syntax error, unexpected ')', expecting kEND
from bin/userscan:3
From what I know, the part it's complaining about -should- be okay. Obviously, the semi-colon is actually supposed to be there and the parenthesis should encompass the entirety of the two lines. I've played around with it a bit, but I just keep making it worse rather than better.
Any assistance with what I'm messing up here would be appreciated.
the syntax host: ".." is new to ruby 1.9. If you are using ruby 1.8, you must use the old syntax:
server = Lumberg::Whm::Server.new(
:host => "localhost",
:hash => IO.read("/root/.accesshash") )

Rails 3.2 with ruby 1.8 syntax problems ( unexpected tASSOC, expecting '}', unexpected ':', expecting kEND)

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

Resources