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

More Related Content

PPTX
Meteor presentation
PDF
Node js quick tour v2
PDF
TechTalk #69 : How to setup and run laravel apps inside vagrant
PDF
Growth Hacking with Jon Eilerman
PPTX
TechTalk #70 : REAL PROGRAMMER USE REGEX
PDF
Your first sinatra app
PDF
Finding Frank - Spotify API.pdf
PDF
East Bay Rails: January 2012
Meteor presentation
Node js quick tour v2
TechTalk #69 : How to setup and run laravel apps inside vagrant
Growth Hacking with Jon Eilerman
TechTalk #70 : REAL PROGRAMMER USE REGEX
Your first sinatra app
Finding Frank - Spotify API.pdf
East Bay Rails: January 2012

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

PDF
Pengantar Ruby on Rails
PPT
A Quick Introduction to Sinatra
PPT
A Quick Introduction to Sinatra
PPTX
Getting started with sinatra
PPTX
PDF
Sinatra: прошлое, будущее и настоящее
Pengantar Ruby on Rails
A Quick Introduction to Sinatra
A Quick Introduction to Sinatra
Getting started with sinatra
Sinatra: прошлое, будущее и настоящее
Ad

More from bincangteknologi (7)

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

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
PPT on Performance Review to get promotions
PPTX
additive manufacturing of ss316l using mig welding
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
DOCX
573137875-Attendance-Management-System-original
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
web development for engineering and engineering
PPTX
Lecture Notes Electrical Wiring System Components
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Welding lecture in detail for understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
R24 SURVEYING LAB MANUAL for civil enggi
PPT on Performance Review to get promotions
additive manufacturing of ss316l using mig welding
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Embodied AI: Ushering in the Next Era of Intelligent Systems
Operating System & Kernel Study Guide-1 - converted.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
573137875-Attendance-Management-System-original
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
web development for engineering and engineering
Lecture Notes Electrical Wiring System Components
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Welding lecture in detail for understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS

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