shoeless joe
shoeless joe

Reputation: 151

strange textEdit behavior in Ruby on OSX. Inserts weird characters in my file

I am having strange textEdit behavior in Ruby on OSX. It inserts weird characters in my file. Please tell me what to do to fix this:

[Goldie-MacBook:~/ruby] jja% cat hello.rb 
#!/usr/bin/ruby
print "Hello World\n"
[Goldie-MacBook:~/ruby] jja% od -c hello.rb 
0000000    #   !   /   u   s   r   /   b   i   n   /   r   u   b   y  \n
0000020    p   r   i   n   t       "   H   e   l   l   o       W   o   r
0000040    l   d   \   n   "  \n                                        
0000046
[Goldie-MacBook:~/ruby] jja% ruby hello.rb 
Hello World
[Goldie-MacBook:~/ruby] jja% lets do some editing
lets: Command not found.
[Goldie-MacBook:~/ruby] jja% cat hello.rb 
#!/usr/bin/ruby
print "Hellooo World!\n”
[Goldie-MacBook:~/ruby] jja% ruby hello.rb
hello.rb:2: unterminated string meets end of file
[Goldie-MacBook:~/ruby] jja% od -c hello.rb 
0000000    #   !   /   u   s   r   /   b   i   n   /   r   u   b   y  \n
0000020    p   r   i   n   t       "   H   e   l   l   o   o   o       W
0000040    o   r   l   d   !   \   n   ”  **  **  \n                    
0000053
[Goldie-MacBook:~/ruby] jja% od -xc hello.rb
0000000      2123    752f    7273    622f    6e69    722f    6275    0a79
           #   !   /   u   s   r   /   b   i   n   /   r   u   b   y  \n
0000020      7270    6e69    2074    4822    6c65    6f6c    6f6f    5720
           p   r   i   n   t       "   H   e   l   l   o   o   o       W
0000040      726f    646c    5c21    e26e    9d80    000a                
           o   r   l   d   !   \   n   ”  **  **  \n                    
0000053
[Goldie-MacBook:~/ruby] jja% ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10]
[Goldie-MacBook:~/ruby] jja% 

Upvotes: 0

Views: 46

Answers (2)

CheeseFry
CheeseFry

Reputation: 1319

@Jordan is right. TextEdit adds things you won't want in your code. If you want a free editor that doesn't do that you can choose resources like atom or text wrangler. Or one of the many other text editors out there.

Upvotes: 0

Jordan Running
Jordan Running

Reputation: 106027

Notice that " and are not the same character. The latter is what's confusing Ruby.

TextEdit uses "Smart Quotes" by default. Under the Edit menu choose Substitutions and uncheck "Smart Quotes." You may also want to uncheck "Smart Dashes."

Upvotes: 1

Related Questions