Wondering about parentheses and spacing


So, In part of Thith Meanth War! I'm told that I can't have a space between the method arguments of gsub! and the method name. I just want to know why this is the case when we can do exactly that for other methods.


# valid
if user_input.include? ("s")
# valid
if user_input.include?("s")
# valid
user_input.gsub!(/s/, "th")
user_input.gsub! (/s/, "th")


This does not need parens, which are ignored, as is the white space.

 > s = "surprise"
=> "surprise"
 > s.include? "s"
=> true
 > s.gsub! (/s/, 'th')
=> "thurprithe"

As we can see it is not invalid in Ruby, so this would be a case where the SCT is examining the code directly, and does not expect that space.


Sorry, I don't understand what you are saying. What is SCT?


I recommend you to read ruby style guide, methods work both ways, but it is a good practice to only omit parentheses for methods without arguments and not to use space before (.


Submission Correctness Test


I see.

The code is fine but Codecademy is looking for something specific so it sees it as invalid?


No so much invalid, but not expected.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.