Skip to content

Commit 46a9a9a

Browse files
author
Anthony Ross
committed
nil is false in ruby
nil is false in ruby so the ternary operator can be used with more idiomatic ruby. Also added a comment to show how to execute with a custom port.
1 parent 6e6ff3a commit 46a9a9a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

server.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
require 'webrick'
1212
require 'json'
1313

14-
port = ENV['PORT'].nil? ? 3000 : ENV['PORT'].to_i
14+
# default port to 3000 or overwrite with PORT variable by running
15+
# $ PORT=3001 ruby server.rb
16+
port = ENV['PORT'] ? ENV['PORT'].to_i : 3000
1517

1618
puts "Server started: http://localhost:#{port}/"
1719

0 commit comments

Comments
 (0)