i cant start webrick

A

Alex Gore

when i try to start webrick i get this message

/easyhtmlserver:12: syntax error, unexpected tASSOC, expecting kEND
:port => 80
^
/easyhtmlserver:14: syntax error, unexpected tASSOC, expecting kEND
:port => 801
^
/easyhtmlserver:11: warning: found = in conditional, should be ==
/easyhtmlserver:16: syntax error, unexpected tSYMBEG, expecting ')'
:DocumentRoot => "/home/" + $home + "/easyhtml/" + $pro
^
/easyhtmlserver:17: syntax error, unexpected ')', expecting kEND
/easyhtmlserver:28: syntax error, unexpected $end, expecting kEND

this is my code

#!/usr/bin/env ruby

#require the libaries
require 'webrick'
include WEBrick

#make the class
class EasyHTMLServer
def initalize
s = HTTPServer.new(
if $port = 80
:port => 80
else
:port => 801
end
:DocumentRoot => "/home/" + $home + "/easyhtml/" + $pro
)
end
end

#declare the varibles
$home = ARGV[0]
$pro = ARGV[1]
$port = ARGV[2]

#load the server
EasyHTMLServer.new
 
B

Ben Lovell

[Note: parts of this message were removed to make it a legal post.]

when i try to start webrick i get this message

./easyhtmlserver:12: syntax error, unexpected tASSOC, expecting kEND
:port => 80
^
./easyhtmlserver:14: syntax error, unexpected tASSOC, expecting kEND
:port => 801
^
./easyhtmlserver:11: warning: found = in conditional, should be ==
./easyhtmlserver:16: syntax error, unexpected tSYMBEG, expecting ')'
:DocumentRoot => "/home/" + $home + "/easyhtml/" + $pro
^
./easyhtmlserver:17: syntax error, unexpected ')', expecting kEND
./easyhtmlserver:28: syntax error, unexpected $end, expecting kEND


This should work:

#make the class
class EasyHTMLServer
def initalize
s = HTTPServer.new(
(if $port = 80
:port => 80
else
:port => 801
end),
:DocumentRoot => "/home/" + $home + "/easyhtml/" + $pro
)
end
end
But that code is pretty nasty to look at.

Regards,
Ben
 
B

Ben Lovell

[Note: parts of this message were removed to make it a legal post.]

This should work:

Sorry, ignore me. I just re-read the post and noticed the problems with with
hash arguments too. Not sure how you solve this.
 
S

spox

when i try to start webrick i get this message

./easyhtmlserver:12: syntax error, unexpected tASSOC, expecting kEND

:port => 80

^
./easyhtmlserver:14: syntax error, unexpected tASSOC, expecting kEND

:port => 801

^
./easyhtmlserver:11: warning: found = in conditional, should be ==
./easyhtmlserver:16: syntax error, unexpected tSYMBEG, expecting ')'

:DocumentRoot => "/home/" + $home + "/easyhtml/" + $pro

^
./easyhtmlserver:17: syntax error, unexpected ')', expecting kEND
./easyhtmlserver:28: syntax error, unexpected $end, expecting kEND

this is my code

#!/usr/bin/env ruby

#require the libaries
require 'webrick'
include WEBrick

#make the class
class EasyHTMLServer
def initalize
s = HTTPServer.new(
if $port = 80

:port => 80

else

:port => 801

end

:DocumentRoot => "/home/" + $home + "/easyhtml/" + $pro

)
end
end

#declare the varibles
$home = ARGV[0]
$pro = ARGV[1]
$port = ARGV[2]

#load the server
EasyHTMLServer.new

s = HTTPServer.new:)Port => $port == 80 ? 80 : 801, :DocumentRoot => 'etc...')
 
J

James Britt

spox said:
s = HTTPServer.new:)Port => $port == 80 ? 80 : 801, :DocumentRoot => 'etc...')


Yikes!

Are people really so adverse to creating simple methods that describe
intent? (They also make testing easier :) )

# Pick a name that makes sense if this is not a good one ...
def default_port default=801
$port == 80 ? 80 : default
end

s = HTTPServer.new :port => default_port, :DocumentRoot => 'etc...'





--
James Britt

www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
www.neurogami.com - Smart application development
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top