Can someone tell me why in the world this doesn’t work? The code below is the entire contents of the file prog.rb
class String
def to_b
return true if self == "true"
false
end
end
Here is the error:
path/prog.rb:1: syntax error, unexpected keyword_def, expecting
<' or ';' or '\n'
return true if self =...
^
There are no bad characters in the file and I’m using Ruby 1.9.3. The code is tested in IRB and found to work.
Is this a bug?
Thanks
My guess is that there’s an issue with how your editor is saving carriage returns. It’s saying it expected a
<or;or\n— which means it didn’t detect the\n(carriage return) that should have been present at the end of theclass Stringline.Check your editor’s carriage return settings and re-save the file.