0

This is the error I get when I do a bundle in the rails repo in the master branch.

There was a SyntaxError while loading arel.gemspec: 
/home/apnabhzu/ruby/gems/bundler/gems/arel-3c429c5d86e9/lib/arel/table.rb:14: syntax
error, unexpected tLABEL
    def initialize(name, as: nil, type_caster: nil)
                            ^
/home/apnabhzu/ruby/gems/bundler/gems/arel-3c429c5d86e9/lib/arel/table.rb:14: Can't
assign to nil
    def initialize(name, as: nil, type_caster: nil)
                                 ^
/home/apnabhzu/ruby/gems/bundler/gems/arel-3c429c5d86e9/lib/arel/table.rb:125: syntax
error, unexpected keyword_end, expecting $end from
  /home/apnabhzu/ruby/gems/bundler/gems/arel-3c429c5d86e9/arel.gemspec:3:in `<main>'

I have listed the environment details below :

  • Ruby Version - 1.9.3p429
  • Rails Version - 5.0.0.alpha
  • Bundler version 1.10.6

I have no idea why I am getting this, what could be a possible fix?

bitsapien
  • 1,753
  • 12
  • 24

1 Answers1

0

Why you are trying to assign nil value to parameter?

The default parameter is used when the parameter isn't provided.

If you provide it as nil, then it will be nil.

If you want to set a default value, even if nil is passed, and still allow calling the method without an argument you need to set the default value to nil and use the "or equals" operator:

def initialize(name,as=nil)
 as ||= "Your value"
 puts as
end
Jenorish
  • 1,694
  • 14
  • 19