Skip to content

Commit

Permalink
nil is false in ruby
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Anthony Ross committed Jan 24, 2016
1 parent 6e6ff3a commit 46a9a9a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
require 'webrick'
require 'json'

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

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

Expand Down

0 comments on commit 46a9a9a

Please sign in to comment.