SlideShare a Scribd company logo
Ruby dan Sinatra
By: Delta Purna Widyangga
| @deltawidyanggad@qiscus.com
Tentang Ruby
A dynamic, open source programming language with
a focus on simplicity and productivity. It has elegant
syntax that is natural to read and easy to write -
ruby-lang.org
Dibuat oleh @matz (Yukihiro Matsumoto)
Public release 1995
Object Oriented
Sekarang versi 2.2.1
https://github.com/ruby/ruby
Why Ruby
"Ruby stays out of your way" (Dave Thomas)
“trying to make Ruby natural, not simple” (Matz)
Imperative with functional flavor (+OO)
Versatile
Great communities ( )RubyGems
Ruby is Versatile
Scripting
Server side web (Rails, Sinatra, etc.)
Client side web (Opal, Volt)
Mobile (Ruby Motion)
Robotics (Artoo)
JVM based app (JRuby)
Ruby.new
def greeting(name);
result = "Hello, " + name;
return result;
end;
puts(greeting("Delta"));
puts(greeting("Puti"));
Ruby.new (Refined)
def greeting(name)
"Hello, #{name}"
end
puts greeting("Delta")
puts greeting("Puti")
No semicolon | return the last expression | optional parentheses |
String interpolation
Object.. Object.. Everywhere
puts "Tech Talk JDV".length
puts "Qiscus".index("c")
puts "Delta Purna".reverse
puts 42.even?
puts nil.to_i
String, FixNum, Everything on ruby land, even nothing is an object
Monkey Patch Everything
class String
def shout!
"#{self.upcase}!!!"
end
end
puts "Tech Talk JDV".shout!
Can doesn't mean you should
class Animal; def walk; "Walking..."; end; end;
class Cat < Animal
def speak
"Meong..."
end
end
puts "#{Cat.new.speak} while #{Cat.new.walk}"
Arrays
my_arr = [ 10, 'qiscus', 1.618 ]
puts "The second element is #{my_arr[1]}"
# set the third element
my_arr[2] = nil
puts "The array is now #{my_arr}"
Hashes
person = {
'name' => 'Delta Purna Widyangga',
'age' => '28',
'job' => 'Programmer'
}
p person['name']
p person['job']
p person['weight']
Blocks (1)
def my_block
puts "Begin"
yield
yield
puts "End"
end
my_block { puts "Inside my block" }
Blocks (2)
def our_programmers
yield "Hiraq", "Backend"
yield "Fikri", "Frontend"
end
our_programmers do |name, role|
puts "#{name} is a #{role} developer"
end
Iterators
[ 'angga', 'oki', 'omayib' ].each {|name| print name, " " }
3.times { print "*" }
2.upto(8) {|i| print i }
('b'..'f').each {|char| print char }
puts
Collections
p [ 1, 2, 3 ].map { |n| n * 2 }
p (1..10).select { |n| n % 2 == 0 }
p [ 10, 20, 30 ].reduce { |sum, n| sum + n }
Ruby for DSL
Ruby is good for creating internal Domain Specific Language (DSL)
tweet_as('deltawidyangga') do
text 'hello world this is my first tweet'
mention 'putiayusetiani'
link 'http://melangkahkesurga.com'
hashtag 'first'
end
tweet_as('deltawidyangga') do
mention 'putiayusetiani'
Tentang Sinatra
Sinatra is a DSL for quickly creating web applications
in Ruby with minimal effort - sinatrarb.com
Dibuat oleh @bmizerany (Blake Mizerany) tahun 2007
Sekarang di maintain oleh @rkh (Konstantin Haase)
Why Sinatra
They are both solving a different set of issues, even
though they indeed overlap. While Rails is a
framework focused on writing model driven web
applications, Sinatra is a library for dealing with
HTTP from the server side. If you think in terms of
HTTP requests/responses, Sinatra is the ideal tool. If
you need full integration and as much boilerplate as
possible, Rails is the way to go. - Konstantin
Sinatra is great for the micro-style, Rails is not. As
long as you stay micro, Sinatra will beat Rails. If you
go beyond micro, Rails will beat Sinatra. - David
Installing Sinatra
Sinatra adalah sebuah gem (library di ruby)
gem install sinatra
https://rubygems.org/gems/sinatra
Hello Sinatra
require 'sinatra'
get '/' do
'Hello Sinatra!'
end
Resources
Komunitas
Untuk Belajar
jogja.rb
id-tech
id-ruby
Belajar Ruby on Rails @qiscus
RoR Semarang
Try Ruby
Belajar Ruby Bahasa Indonesia
Codecademy Ruby
Learn Ruby the Hard Way
The Pickaxe Book
Sinatra README
Sinatra Book
Ad

More Related Content

Similar to TechTalk #67 : Introduction to Ruby and Sinatra (20)

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
Michael MacDonald
 
The story of language development
The story of language developmentThe story of language development
The story of language development
Hiroshi SHIBATA
 
NATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist MeetupNATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist Meetup
wallyqs
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
Mark Menard
 
Build Your Own Tools
Build Your Own ToolsBuild Your Own Tools
Build Your Own Tools
Shugo Maeda
 
Initiation à Ruby on Rails
Initiation à Ruby on RailsInitiation à Ruby on Rails
Initiation à Ruby on Rails
Microsoft Technet France
 
Introduction to node
Introduction to nodeIntroduction to node
Introduction to node
girish82
 
From Java to Ruby...and Back
From Java to Ruby...and BackFrom Java to Ruby...and Back
From Java to Ruby...and Back
Anil Hemrajani
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the Rubyist
Will Green
 
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
Salesforce Marketing Cloud
 
Ruby, Rails, and the Open Source Community
Ruby, Rails, and the Open Source CommunityRuby, Rails, and the Open Source Community
Ruby, Rails, and the Open Source Community
Jim Myhrberg
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Habeeb Rahman
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
Thomas Asikis
 
Web application intro
Web application introWeb application intro
Web application intro
Tobias Pfeiffer
 
l-rubysocks-a4
l-rubysocks-a4l-rubysocks-a4
l-rubysocks-a4
tutorialsruby
 
l-rubysocks-a4
l-rubysocks-a4l-rubysocks-a4
l-rubysocks-a4
tutorialsruby
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Eugene Yokota
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
Sinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящееSinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящее
.toster
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
TAInteractive
 
The story of language development
The story of language developmentThe story of language development
The story of language development
Hiroshi SHIBATA
 
NATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist MeetupNATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist Meetup
wallyqs
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
Mark Menard
 
Build Your Own Tools
Build Your Own ToolsBuild Your Own Tools
Build Your Own Tools
Shugo Maeda
 
Introduction to node
Introduction to nodeIntroduction to node
Introduction to node
girish82
 
From Java to Ruby...and Back
From Java to Ruby...and BackFrom Java to Ruby...and Back
From Java to Ruby...and Back
Anil Hemrajani
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the Rubyist
Will Green
 
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
Salesforce Marketing Cloud
 
Ruby, Rails, and the Open Source Community
Ruby, Rails, and the Open Source CommunityRuby, Rails, and the Open Source Community
Ruby, Rails, and the Open Source Community
Jim Myhrberg
 
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled InfrastructureCloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Cloud meets Fog & Puppet A Story of Version Controlled Infrastructure
Habeeb Rahman
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
Thomas Asikis
 
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)Road to sbt 1.0: Paved with server (2015 Amsterdam)
Road to sbt 1.0: Paved with server (2015 Amsterdam)
Eugene Yokota
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
Sinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящееSinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящее
.toster
 

More from bincangteknologi (7)

TechTalk #86 : ECMAScript 6 by Afief S
TechTalk #86 : ECMAScript 6 by Afief STechTalk #86 : ECMAScript 6 by Afief S
TechTalk #86 : ECMAScript 6 by Afief S
bincangteknologi
 
TechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend TechnologiesTechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend Technologies
bincangteknologi
 
Intro to Chef
Intro to ChefIntro to Chef
Intro to Chef
bincangteknologi
 
Qiscus enterprice for Hotels
Qiscus enterprice for HotelsQiscus enterprice for Hotels
Qiscus enterprice for Hotels
bincangteknologi
 
Ddd part 2 modelling qiscus
Ddd part 2   modelling qiscusDdd part 2   modelling qiscus
Ddd part 2 modelling qiscus
bincangteknologi
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"
bincangteknologi
 
Arduino + Android
Arduino + AndroidArduino + Android
Arduino + Android
bincangteknologi
 
TechTalk #86 : ECMAScript 6 by Afief S
TechTalk #86 : ECMAScript 6 by Afief STechTalk #86 : ECMAScript 6 by Afief S
TechTalk #86 : ECMAScript 6 by Afief S
bincangteknologi
 
TechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend TechnologiesTechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend Technologies
bincangteknologi
 
Qiscus enterprice for Hotels
Qiscus enterprice for HotelsQiscus enterprice for Hotels
Qiscus enterprice for Hotels
bincangteknologi
 
Ddd part 2 modelling qiscus
Ddd part 2   modelling qiscusDdd part 2   modelling qiscus
Ddd part 2 modelling qiscus
bincangteknologi
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"
bincangteknologi
 
Ad

Recently uploaded (20)

The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Machine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptxMachine learning project on employee attrition detection using (2).pptx
Machine learning project on employee attrition detection using (2).pptx
rajeswari89780
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Ad

TechTalk #67 : Introduction to Ruby and Sinatra

  • 1. Ruby dan Sinatra By: Delta Purna Widyangga | @[email protected]
  • 2. Tentang Ruby A dynamic, open source programming language with a focus on simplicity and productivity. It has elegant syntax that is natural to read and easy to write - ruby-lang.org Dibuat oleh @matz (Yukihiro Matsumoto) Public release 1995 Object Oriented Sekarang versi 2.2.1 https://github.com/ruby/ruby
  • 3. Why Ruby "Ruby stays out of your way" (Dave Thomas) “trying to make Ruby natural, not simple” (Matz) Imperative with functional flavor (+OO) Versatile Great communities ( )RubyGems
  • 4. Ruby is Versatile Scripting Server side web (Rails, Sinatra, etc.) Client side web (Opal, Volt) Mobile (Ruby Motion) Robotics (Artoo) JVM based app (JRuby)
  • 5. Ruby.new def greeting(name); result = "Hello, " + name; return result; end; puts(greeting("Delta")); puts(greeting("Puti"));
  • 6. Ruby.new (Refined) def greeting(name) "Hello, #{name}" end puts greeting("Delta") puts greeting("Puti") No semicolon | return the last expression | optional parentheses | String interpolation
  • 7. Object.. Object.. Everywhere puts "Tech Talk JDV".length puts "Qiscus".index("c") puts "Delta Purna".reverse puts 42.even? puts nil.to_i String, FixNum, Everything on ruby land, even nothing is an object
  • 8. Monkey Patch Everything class String def shout! "#{self.upcase}!!!" end end puts "Tech Talk JDV".shout!
  • 9. Can doesn't mean you should class Animal; def walk; "Walking..."; end; end; class Cat < Animal def speak "Meong..." end end puts "#{Cat.new.speak} while #{Cat.new.walk}"
  • 10. Arrays my_arr = [ 10, 'qiscus', 1.618 ] puts "The second element is #{my_arr[1]}" # set the third element my_arr[2] = nil puts "The array is now #{my_arr}"
  • 11. Hashes person = { 'name' => 'Delta Purna Widyangga', 'age' => '28', 'job' => 'Programmer' } p person['name'] p person['job'] p person['weight']
  • 12. Blocks (1) def my_block puts "Begin" yield yield puts "End" end my_block { puts "Inside my block" }
  • 13. Blocks (2) def our_programmers yield "Hiraq", "Backend" yield "Fikri", "Frontend" end our_programmers do |name, role| puts "#{name} is a #{role} developer" end
  • 14. Iterators [ 'angga', 'oki', 'omayib' ].each {|name| print name, " " } 3.times { print "*" } 2.upto(8) {|i| print i } ('b'..'f').each {|char| print char } puts
  • 15. Collections p [ 1, 2, 3 ].map { |n| n * 2 } p (1..10).select { |n| n % 2 == 0 } p [ 10, 20, 30 ].reduce { |sum, n| sum + n }
  • 16. Ruby for DSL Ruby is good for creating internal Domain Specific Language (DSL) tweet_as('deltawidyangga') do text 'hello world this is my first tweet' mention 'putiayusetiani' link 'http://melangkahkesurga.com' hashtag 'first' end tweet_as('deltawidyangga') do mention 'putiayusetiani'
  • 17. Tentang Sinatra Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort - sinatrarb.com Dibuat oleh @bmizerany (Blake Mizerany) tahun 2007 Sekarang di maintain oleh @rkh (Konstantin Haase)
  • 18. Why Sinatra They are both solving a different set of issues, even though they indeed overlap. While Rails is a framework focused on writing model driven web applications, Sinatra is a library for dealing with HTTP from the server side. If you think in terms of HTTP requests/responses, Sinatra is the ideal tool. If you need full integration and as much boilerplate as possible, Rails is the way to go. - Konstantin Sinatra is great for the micro-style, Rails is not. As long as you stay micro, Sinatra will beat Rails. If you go beyond micro, Rails will beat Sinatra. - David
  • 19. Installing Sinatra Sinatra adalah sebuah gem (library di ruby) gem install sinatra https://rubygems.org/gems/sinatra
  • 20. Hello Sinatra require 'sinatra' get '/' do 'Hello Sinatra!' end
  • 21. Resources Komunitas Untuk Belajar jogja.rb id-tech id-ruby Belajar Ruby on Rails @qiscus RoR Semarang Try Ruby Belajar Ruby Bahasa Indonesia Codecademy Ruby Learn Ruby the Hard Way The Pickaxe Book Sinatra README Sinatra Book