Ruby: Ubuntu Gedit Problem possible with Spaces
can someone tell me why this works in my gedit on ubuntu
def initialize (product_id,category_id,category_name)
but this does not. It thows a syntax error and says that I am missing a ")"
def initialize (product_id, category_id, category_name)
I spent about 2 hours running through all the rest of my code and this开发者_如何学运维 is what fixed the syntax error. I had to change it where I call the method and in its definition. The rest of my code is 100% the same.. Is gedit doing something with my spaces? Thanks
You're not supposed to have a space between the method name and the arguments list for that method. It should be:
def initialize(product_id, category_id, category_name)
While agreeing with @Ryan that you shouldn't have a space between initialize and the bracket, both versions worked fine in IRB for me:
class Foo
def initialize (product_id,category_id,category_name)
end
end
class Bar
def initialize (product_id, category_id, category_name)
end
end
Foo.new(1, 2, 3)
Bar.new(1, 2, 3)
Given these versions of irb on karmic koala:
agrimm@csb1:~$ irb --version
irb 0.9.5(05/04/13)
agrimm@csb1:~$ irb1.9.1 --version
irb 0.9.5(05/04/13)
So if gedit is refusing to accept the code, it's being a bit lazy.
As a side note, you should provide the error's stack trace (so long as it doesn't have top secret information), and ideally provide code like I have above so someone can cut and paste it into their computer. Make it easier for us!
精彩评论