1

Environment

  • Ruby [1.9.3p547]
  • Rails [3.2.22.5]
  • sendgrid-ruby [4.0.8]

I used sendgrid-ruby gem in my application whenever I run rails server it's giving me below error which comes from gems/sendgrid-ruby-4.0.8/lib/sendgrid/client.rb:17

/.rvm/gems/ruby-1.9.3-p547@demo/gems/sendgrid-ruby-4.0.8/lib/sendgrid-ruby.rb:1:in `require_relative': /.rvm/gems/ruby-1.9.3-p547@demo/gems/sendgrid-ruby-4.0.8/lib/sendgrid/client.rb:17: syntax error, unexpected tLABEL, expecting ')' (SyntaxError) def initialize(api_key: nil, host: nil, request_head... ^ /.rvm/gems/ruby-1.9.3-p547@demo/gems/sendgrid-ruby-4.0.8/lib/sendgrid/client.rb:17: Can't assign to nil ... def initialize(api_key: nil, host: nil, request_headers: ... ... ^ /.rvm/gems/ruby-1.9.3-p547@demo/gems/sendgrid-ruby-4.0.8/lib/sendgrid/client.rb:17: Can't assign to nil ...ialize(api_key: nil, host: nil, request_headers: nil, versio... ... ^ /.rvm/gems/ruby-1.9.3-p547@demo/gems/sendgrid-ruby-4.0.8/lib/sendgrid/client.rb:17: Can't assign to nil ...ost: nil, request_headers: nil, version: nil)

I checked the same file and same line of gem sengrid-ruby. it has below the line

def initialize(api_key: nil, host: nil, request_headers: nil, version: nil)

if I replace this to below it isn't giving me.

def initialize(api_key, host, request_headers, version)

is this syntax error of rails or ruby related version? There are other lots of error which contain the same syntax in other gems. What should I do with this type of syntax errors?

Vishal
  • 7,113
  • 6
  • 31
  • 61

1 Answers1

4

Keyword arguments require Ruby's version 2.0.0 or higher. https://thoughtbot.com/blog/ruby-2-keyword-arguments

Ursus
  • 29,643
  • 3
  • 33
  • 50
  • if i used ruby version `1.9.3p547` then gem `sendgrid-ruby` should also take version based on ruby version. right? – Vishal Apr 17 '19 at 13:00
  • Nope, they wrote the code with a specific ruby's version – Ursus Apr 17 '19 at 13:01
  • Look at the link. Each version has a specific `REQUIRED RUBY VERSION` – Ursus Apr 17 '19 at 13:02
  • I'd try version 3.0.3 for sendgrid-ruby gem – Ursus Apr 17 '19 at 13:03
  • yes, i checked but look at this `https://rubygems.org/gems/sendgrid-ruby/versions` for version 3.0.4 ruby version should be 2.2 or higher but for gem version 3.0.3 ruby version should be higher then 0.0 . – Vishal Apr 17 '19 at 13:04
  • Yes, I saw that. Try 3.0.3, it seems the last one before they had used ruby 2.2 – Ursus Apr 17 '19 at 13:05
  • Yes, that might happen. but it should take version 3.0.3 . based on ruby version. – Vishal Apr 17 '19 at 13:06
  • You choose the versions of the gems. It's not something automatic – Ursus Apr 17 '19 at 13:08
  • I used version 3.0.3, then also it's giving me the same syntax error. ` * sendgrid-ruby (3.0.3) ` – Vishal Apr 17 '19 at 13:12
  • Change tag, and see if they used keyword arguments or not. In fact it seems they used even in 3.0.3. but older versions not – Ursus Apr 17 '19 at 13:16
  • You can see the code for a specific tag. And tags match to versions usually. You can see if they use keyworkd arguments for a specific version. – Ursus Apr 17 '19 at 14:19