Wondering about parentheses and spacing


#1



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.


https://www.codecademy.com/en/courses/ruby-beginner-en-JdNDe/0/5?curriculum_id=5059f8619189a5000201fbcb


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


#2

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.


#3

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


#4

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 (.


#5

Submission Correctness Test


#6

I see.

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


#7

No so much invalid, but not expected.


#8

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