Take the 2-minute tour ×

Attempting to execute the basic.rb example for HTTParty. Running into an interesting error. Executing this under 1.8.7 on my Mac (10.7.2). When I run the example (see code below), I get this error:

$ ./HTTPartyTest.rb
./HTTPartyTest.rb: line 1: syntax error near unexpected token `('
./HTTPartyTest.rb: line 1: `dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))'

If I take line 1 and execute it via irb I get this result.

=> "/Users/me/Workspaces/lib"

Not sure why this occurring. Any help is appreciated.

share|improve this question
Does dir = File.expand_path(File.join(File.dirname(FILE), '../', 'lib')) give the same result? It did the same thing in irb here as without the slash. –  Douglas G. Allen May 24 '13 at 4:57

1 Answer 1

You probably need to add the correct hash-bang header or this will be executed using your shell instead:

#!/usr/bin/env ruby

# ... (Rest of program)

The alternative is to explicitly specify you want to run it with Ruby:

ruby ./HTTPartyTest.rb
share|improve this answer
Thanks. That did it. –  floresmd Feb 5 '12 at 1:59
Can you mark it as answered then... –  Bealer Jul 26 '12 at 21:12

Your Answer


