|# this Ruby method definiton will get defined successfuly|
|# but this Ruby method definiton will Fail with syntax error: syntax error, unexpected keyword_end, expecting end-of-input|
|# Question on you: Why didn't the first example throw syntax error ? :)|
|# Who will figure it out first ? :)|
We have winners
(delay of first two answer was like 1 minute so close win :) )
Answer to this question:
First example is defined with different UTF-8 whitespace character . Second example is defined with normal regular space.
There are different "white space" characters in UTF-8 world (e.g. Tab, no-brake spaces etc) defined in UTF-8 char set http://jkorpela.fi/chars/spaces.htm, Ruby supports UTF-8 code. (Ruby since v 1.9 I think)
So if you want to mess around with your college define method like this:
def my_method "what sorcery is this !?" end my_method # => "what sorcery is this !?" my_method # => NameError (undefined local variable or method `my_method' for main:Object)
It looks like an empty space.
Ruby allows creating methods using Unicode characters.
An empty space is not a valid method name in Ruby.
Because the 1st definition uses an empty-looking character in the Unicode character set Ruby considers this a valid method name, but the 2nd definition uses an actual empty space, which is not valid.