開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Ruby 2.3 (プログラミング言語)
Head First Ruby (Jay McGavren (著)、O'Reilly Media)のChapter 14.(Web Apps: Serving HTML)、ERB embedding tags、Pool Puzzle(No. 7404)を取り組んでみる。
Pool Puzzle(No. 7404)
コード(Emacs)
#!/usr/bin/env ruby2.3
# -*- coding: utf-8 -*
require 'sinatra'
get('/addition') do
@first = 3
@second = 5
@result = @first + @second
erb :addition
end
get('/multiplication') do
@first = 2
@second = 6
@result = @first * @second
erb :multiplication
end
<!doctype html>
<html>
<body>
<%= @first %> plus
<%= @second %> equals
<%= @result %>
</body>
</html>
<!doctype html>
<html>
<body>
<%= @first %> times
<%= @second %> equals
<%= @result %>
</body>
</html>
入出力結果(Terminal)
$ ./app.rb [2016-10-03 18:49:42] INFO WEBrick 1.3.1 [2016-10-03 18:49:42] INFO ruby 2.3.1 (2016-04-26) [x86_64-darwin15] == Sinatra (v1.4.7) has taken the stage on 4567 for development with backup from WEBrick [2016-10-03 18:49:42] INFO WEBrick::HTTPServer#start: pid=11073 port=4567 ::1 - - [03/Oct/2016:18:49:54 +0900] "GET /addition HTTP/1.1" 200 79 0.0237 ::1 - - [03/Oct/2016:18:49:54 JST] "GET /addition HTTP/1.1" 200 79 - -> /addition ::1 - - [03/Oct/2016:18:50:04 +0900] "GET /multiplication HTTP/1.1" 200 81 0.0042 ::1 - - [03/Oct/2016:18:50:04 JST] "GET /multiplication HTTP/1.1" 200 81 - -> /multiplication C-c C-c== Sinatra has ended his set (crowd applauds) [2016-10-03 18:50:10] INFO going to shutdown ... [2016-10-03 18:50:10] INFO WEBrick::HTTPServer#start done. $
0 コメント:
コメントを投稿