0

When I am trying to initialize this it is working perfectly fine

class Abc def initialize(parent_id, user = nil, permission) end end Abc.new(1 ,2, "some_permission") 

But when I am doing this

 class Abc def initialize(parent_id, user = nil, permission, g_data = nil) end end 

Abc.new(1 ,2, "some_permission", 4)

I am getting syntax error syntax error, unexpected '=', expecting ')' This is a strange behavior why it is not taking two arguments default as nil

1 Answer 1

2

According to ruby documentation the default values should be grouped.

The default value does not need to appear first, but arguments with defaults must be grouped together.

So according to this rule your method arguments should be listed like following:

 class Abc def initialize(parent_id, user = nil,g_data = nil,permission) end # OR def initialize(parent_id, permission,user = nil,g_data = nil) end end 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.