SlideShare a Scribd company logo
1 of 21
Download to read offline
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

More Related Content

Similar to TechTalk #67 : Introduction to Ruby and Sinatra

The story of language development
The story of language developmentThe story of language development
The story of language developmentHiroshi SHIBATA
 
NATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist MeetupNATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist Meetupwallyqs
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Mark Menard
 
Build Your Own Tools
Build Your Own ToolsBuild Your Own Tools
Build Your Own ToolsShugo Maeda
 
Introduction to node
Introduction to nodeIntroduction to node
Introduction to nodegirish82
 
From Java to Ruby...and Back
From Java to Ruby...and BackFrom Java to Ruby...and Back
From Java to Ruby...and BackAnil Hemrajani
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the RubyistWill 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 SpeedSalesforce 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 CommunityJim 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 InfrastructureHabeeb Rahman
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overviewThomas 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-phpapp02sagaroceanic11
 
Sinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящееSinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящее.toster
 

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
 
The story of language development
The story of language developmentThe story of language development
The story of language development
 
NATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist MeetupNATS for Rubyists - Tokyo Rubyist Meetup
NATS for Rubyists - Tokyo Rubyist Meetup
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Build Your Own Tools
Build Your Own ToolsBuild Your Own Tools
Build Your Own Tools
 
Initiation à Ruby on Rails
Initiation à Ruby on RailsInitiation à Ruby on Rails
Initiation à Ruby on Rails
 
Introduction to node
Introduction to nodeIntroduction to node
Introduction to node
 
From Java to Ruby...and Back
From Java to Ruby...and BackFrom Java to Ruby...and Back
From Java to Ruby...and Back
 
IronRuby for the Rubyist
IronRuby for the RubyistIronRuby for the Rubyist
IronRuby for the Rubyist
 
#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
 
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
 
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
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
 
Web application intro
Web application introWeb application intro
Web application intro
 
l-rubysocks-a4
l-rubysocks-a4l-rubysocks-a4
l-rubysocks-a4
 
l-rubysocks-a4
l-rubysocks-a4l-rubysocks-a4
l-rubysocks-a4
 
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)
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02
 
Sinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящееSinatra: прошлое, будущее и настоящее
Sinatra: прошлое, будущее и настоящее
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 

More from 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 Sbincangteknologi
 
TechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend TechnologiesTechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend Technologiesbincangteknologi
 
Qiscus enterprice for Hotels
Qiscus enterprice for HotelsQiscus enterprice for Hotels
Qiscus enterprice for Hotelsbincangteknologi
 
Ddd part 2 modelling qiscus
Ddd part 2   modelling qiscusDdd part 2   modelling qiscus
Ddd part 2 modelling qiscusbincangteknologi
 
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
 

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
 
TechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend TechnologiesTechTalk #85 : Latest Frontend Technologies
TechTalk #85 : Latest Frontend Technologies
 
Intro to Chef
Intro to ChefIntro to Chef
Intro to Chef
 
Qiscus enterprice for Hotels
Qiscus enterprice for HotelsQiscus enterprice for Hotels
Qiscus enterprice for Hotels
 
Ddd part 2 modelling qiscus
Ddd part 2   modelling qiscusDdd part 2   modelling qiscus
Ddd part 2 modelling qiscus
 
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"
 
Arduino + Android
Arduino + AndroidArduino + Android
Arduino + Android
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 

TechTalk #67 : Introduction to Ruby and Sinatra

  • 1. Ruby dan Sinatra By: Delta Purna Widyangga | @deltawidyanggad@qiscus.com
  • 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