0

Can someone please explain the meaning of (!) In Ruby

I've been looking on the internet for ages and I just can't seem to find a place that explains what the (!) symbol means and does......

31st Dec 2016, 2:14 AM
Kyle Selander
Kyle Selander - avatar
4 ответов
+ 3
Its the negation of a logic sentence
31st Dec 2016, 2:23 AM
Nahuel
Nahuel - avatar
+ 2
An exclamation point refers to NOT something, such as 'not equal' or 'not greater', for example (a > 5), means that a is greater than 5, but with an exclamation point (a !> 5) means a is NOT greater than 5.
31st Dec 2016, 2:26 AM
Jose Ayala
Jose Ayala - avatar
0
there's also another use, when it appears after a method. It basically means that you can call a method inside a variable and automatically store the return value inside the same variable..... Maybe it's easier to understand with some code: text = "hello" # Store a string inside the text variable #=>"hello" text.upcase # Call method upcase to variable text #=>"HELLO" text # Call the text variable again, it's value is still in lowercase #=>"hello" text.upcase! # This time, call the method and store the return value inside the text variable #=>"HELLO" text # Now, the value of text is in uppercase, without having to explicity reassign its value #=>"HELLO"
31st Dec 2016, 4:06 AM
Alejandro Aristizabal
Alejandro Aristizabal - avatar
0
A simpler way to explain this is: text = text.upcase is the same as text.upcase!
31st Dec 2016, 4:07 AM
Alejandro Aristizabal
Alejandro Aristizabal - avatar