SlideShare a Scribd company logo
1 of 43
Download to read offline
Ruby
 programming language
         and
Ruby on Rails framework
Presentation Agenda
 What is Ruby?

 About the language

 Its history

 Principles of language

 Code examples

 Rails framework

January 18, 2010        Radek Mika - Unicorn College   2
What is Ruby?
 Programming language

 Interpreted language

 Modern language

 Object-oriented language

 Dynamically typed language

 Agile language



January 18, 2010         Radek Mika - Unicorn College   3
Principles of Ruby




January 18, 2010        Radek Mika - Unicorn College   4
Principles of Ruby




January 18, 2010        Radek Mika - Unicorn College   5
Principles of Ruby
 Japanese Design

       Focus on human factor

       Principle of Least Surprise

       Principle of Least Effort



January 18, 2010         Radek Mika - Unicorn College   6
The Principle of Least Surprise
This principle is the supreme design goal of Ruby
       It makes programmers happy
       It makes Ruby easy to learn
Examples
      What class is an object?
                   o.class
      Is it Array.size or Array.length?
                   same method - they are aliased
      What are the differences between arrays?
                   Diff = ary1 – ary2
                   Union = ary1 + ary2

January 18, 2010               Radek Mika - Unicorn College   7
The Principle of Least Effort
 We do not like to waste time
           Especially on XML configuration files, getters, setters, etc.


 Syntactic sugar wherever you look

 The quicker we program, the more we accomplish
           Sounds reasonable enough, does not it?


 Less code means less bugs



January 18, 2010                   Radek Mika - Unicorn College            8
Philosophy
 No perfect language

 Have joy

 Computers are my servants, not my masters!

 Unchangeable small core (syntax) and extensible class
  libraries



January 18, 2010        Radek Mika - Unicorn College      9
The History of Ruby
 Created in Japan 10 years ago

 Created by Yukihiro Matsumoto (known as
  Matz)

 Inspired by Perl, Python, Lisp and Smalltalk



January 18, 2010        Radek Mika - Unicorn College   10
Comparison with Python
 Interactive prompt (similar)
 No special line terminator (similar)
 Everything is an object (similar)


                     X
 More speed! (ruby is faster)
  …
January 18, 2010          Radek Mika - Unicorn College   11
Ruby is Truly Object-Oriented
 Ruby uses single inheritance
           X
 Mixins and Modules allow you to extend classes
  without multiple inheritance

 Reflection

 Things like ‘=’ and ‘+’ which may appear as
  operators are actually methods (like Smalltalk)

January 18, 2010    Radek Mika - Unicorn College    12
Well, that’s all nice but…




                       …is it FAST?
January 18, 2010           Radek Mika - Unicorn College   13
Merge Sort Algorithm




January 18, 2010       Radek Mika - Unicorn College   14
Ruby Speed Comparison

 3x faster than      PHP

 2.5x faster than    Perl

 2x faster than      Python



 2x (maybe more)     C++
 SLOWER than




January 18, 2010              Radek Mika - Unicorn College   15
Ruby Speed - WARNING


 Previous results are only
 informational (only Merge Sort
 Comparison)

 Another comparisons usually
 have different results




January 18, 2010         Radek Mika - Unicorn College   16
When I should not use Ruby?
 If I need highly effective and powerful language, e.g.
  for distributed calculations
 If I want to write a complicated, ugly or messy code


     Other disadvantages:


 Less spread than Perl is
 Ruby is relatively slow

January 18, 2010       Radek Mika - Unicorn College        17
And finally…




                   …some code examples
January 18, 2010         Radek Mika - Unicorn College   18
Clear Syntax
# Output "UPPER"
puts "upper".upcase

# Output the absolute value of -5:
puts -5.abs

# Output "Ruby Rocks!" 5 times
5.times do
  puts "Ruby Rocks!"
end
Source: http://pastie.org/785234


January 18, 2010                   Radek Mika - Unicorn College   19
Classes and Methods
#Classes begin with class and end with end:
# The Greeter class
class Greeter
end

#Methods begin with def and end with end:
# The salute method
def salute
end
Source: http://pastie.org/785249


January 18, 2010                   Radek Mika - Unicorn College   20
Classes and Methods
# The Greeter class
class Greeter
  def initialize(greeting)
    @greeting = greeting
  end

  def salute(name)
    puts "#{@greeting} #{name}!"
  end
end

# Initialize our Greeter
g = Greeter.new("Hello")

# Output "Hello World!"
g.salute("World")

Source: http://pastie.org/785258 - classes


January 18, 2010                     Radek Mika - Unicorn College   21
If Statements
# if with several branches
if account.total > 100000
  puts "large account"
elsif account.total > 25000
  puts "medium account"
else
  puts "small account„
end
Sources: http://pastie.org/785268



January 18, 2010                    Radek Mika - Unicorn College   22
Case Statements
# A simple case/when statement
case name
when "John"
  puts "Howdy John!"
when "Ryan"
  puts "Whatz up Ryan!"
else
  puts "Hi #{name}!"
end
Sources: http://pastie.org/785278


January 18, 2010                    Radek Mika - Unicorn College   23
Regular Expressions
#Ruby supports Perl-style regular expressions:
# Extract the parts of a phone number

phone = "123-456-7890"

if phone           =~ /(d{3})-(d{3})-(d{4})/
  ext =            $1
  city =           $2
  num =            $3
end
Sources: http://pastie.org/785732


January 18, 2010                    Radek Mika - Unicorn College   24
Regular Expressions
# Case statement with regular expression
case lang
when /ruby/i
  puts "Matz created Ruby!"
when /perl/i
  puts "Larry created Perl!"
else
  puts "I don't know who created #{lang}."
end
Sources: http://pastie.org/785738



January 18, 2010                    Radek Mika - Unicorn College   25
Ruby Blocks
# Print out a list of people from
# each person in the Array
people.each do |person|
  puts "* #{person.name}"
end

# A block using the bracket syntax
5.times { puts "Ruby rocks!" }

# Custom sorting
[2,1,3].sort! { |a, b| b <=> a }

Sources: http://pastie.org/pastes/785239



January 18, 2010                     Radek Mika - Unicorn College   26
Yield to the Block!
# define the thrice method
def thrice
  yield
  yield
  yield
end

# Output "Blocks are cool!" three times
thrice { puts "Blocks are cool!" }

#This example use yield from within a method to
#hand control over to a block:
Sources: http://pastie.org/785774



January 18, 2010                    Radek Mika - Unicorn College   27
Blocks with Parameters
# redefine the thrice method
def thrice
  yield(1)
  yield(2)
  yield(3)
end

# Output "Blocks are cool!" three times,
# prefix it with the count
thrice { | i |
  puts "#{i}: Blocks are cool!"
}
Sources: http://pastie.org/785789



January 18, 2010                    Radek Mika - Unicorn College   28
Enough talking about Ruby!...




              What about Ruby on Rails?
January 18, 2010      Radek Mika - Unicorn College   29
Ruby on Rails
 Web framework

 An extremely productive web-application
  framework that is written in Ruby by
  David Hansson

 Includes everything needed to create database-driven web
  applications according to the Model-View-Control pattern
  of separation

 So-called reason of spreading ruby


January 18, 2010       Radek Mika - Unicorn College      30
Ruby on Rails
 MVC

 Convention over Configurations

 Don’t Repeat Yourself (DRY)




January 18, 2010     Radek Mika - Unicorn College   31
History
 Predominantly written by David H. Hannson
       Talented designer
       His dream is to change the world
       A 37signals.com principal – World class designers


 Since 2005



January 18, 2010        Radek Mika - Unicorn College        32
Model – View - Controller
 MVC is an architectural pattern, used not only for building web
  applications

 Model classes are the "smart" domain objects (such as Account,
  Product, Person, Post) that hold business logic and know how to
  persist themselves to a database

 Views are HTML templates

 Controllers handle incoming requests (such as Save New Account,
  Update Product, Show Post) by manipulating the model and
  directing data to the view



January 18, 2010           Radek Mika - Unicorn College             33
Active Record
Object/Relational Mapping Framework = Active Record

 Automatic mapping between columns and class
  attributes
 Declarative configuration via macros
 Dynamic finders
 Associations, Aggregations, Tree and List Behaviors
 Locking
 Lifecycle Callbacks
 Single-table inheritance supported
 Validation rules

January 18, 2010       Radek Mika - Unicorn College     34
From Controller to View
Rails gives you many rendering options

 Default template rendering
             Just follow naming conventions and magic happens.


 Explicitly render to particular action

 Redirect to another action

 Render a string response (or no response)
January 18, 2010                 Radek Mika - Unicorn College    35
View Template
ERB –Embedded Ruby

 Similar to JSPs <% and <%= syntax

 Easy to learn and teach for designers

 Execute in scope of controller

 Denoted with .rhtml extension

January 18, 2010      Radek Mika - Unicorn College   36
View Template
XmlMarkup –Programmatic View Construction

 Great for writing xhtml and xml content

 Denoted with .rxml extension

 Embeddable in ERB templates

January 18, 2010      Radek Mika - Unicorn College   37
And Much More…
    Templates and partials
    Pagination
    Caching (page, fragment, action)
    Helpers
    Routing with routes.rb
    Exceptions
    Unit testing
    ActiveSupport API (date conversion, time calculations)
    ActionMailer API
    ActionWebService API
    Rake

January 18, 2010          Radek Mika - Unicorn College        38
Sources
   Ruby on Rails (Agile Atlanta Group) – Obie Fernandez – May 10 ’05
   Ruby Language Overview – Muhamad Admin Rastgee
   Ruby on Rails – Curt Hibbs
   Workin’ on the Rails Road – Obie Fernandez
   Get to the Point! (Development with Ruby on Rails) – Ryan Platte, John W. Long

   Ruby speed comparison (http://is.gd/70hjD)

   http://en.wikipedia.org/wiki/Ruby_on_Rails




January 18, 2010                 Radek Mika - Unicorn College                        39
External Links
   http://ruby-lang.org – official website

   http://www.ruby-doc.org/ - Ruby doc project

   http://rubyforge.org/ - projects in Ruby

   http://www.rubycentral.com/book/ - online book Programming Ruby

   Full Ruby on Rails Tutorial

   Euruko 2008 - videos from European Ruby Conference 2008 in Prague on avc-
    cvut.cz (Czech)



January 18, 2010                  Radek Mika - Unicorn College                  40
Between Q&A…
   … you can run this code …




     … do you still think that you have a fast computer? :)


January 18, 2010        Radek Mika - Unicorn College          41
Acknowledgments & Contact

    Special thanks to Mgr. Veronika Kaplanová for English correction.




                       Radek Mika
                        radek@radekmika.cz
                        @radekmika (twitter)


January 18, 2010           Radek Mika - Unicorn College             42
January 18, 2010   Radek Mika - Unicorn College   43

More Related Content

What's hot

Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksMarcus Denker
 
Joseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about ArchitectureJoseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about ArchitectureHironori Washizaki
 
The Evolution of the Hadoop Ecosystem
The Evolution of the Hadoop EcosystemThe Evolution of the Hadoop Ecosystem
The Evolution of the Hadoop EcosystemCloudera, Inc.
 
REST Problems
REST ProblemsREST Problems
REST Problemspredic8
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewBrett Meyer
 
Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...
Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...
Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...Leinylson Fontinele
 
Mutexes, Monitores e Semáforos
Mutexes, Monitores e SemáforosMutexes, Monitores e Semáforos
Mutexes, Monitores e SemáforosThiago Poiani
 
Design Pattern - Những công thức vàng trong thiết kế
Design Pattern - Những công thức vàng trong thiết kếDesign Pattern - Những công thức vàng trong thiết kế
Design Pattern - Những công thức vàng trong thiết kếNhật Nguyễn Khắc
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
API Design and WebSocket
API Design and WebSocketAPI Design and WebSocket
API Design and WebSocketFrank Greco
 
CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly Sam Bowne
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in JavaIonut Bilica
 
Embracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with FlywayEmbracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with FlywayRed Gate Software
 
Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes Jonathan Salwan
 
Transforming to Microservices
Transforming to MicroservicesTransforming to Microservices
Transforming to MicroservicesKyle Brown
 

What's hot (20)

Lecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinksLecture: Advanced Reflection. MetaLinks
Lecture: Advanced Reflection. MetaLinks
 
Joseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about ArchitectureJoseph Yoder : Being Agile about Architecture
Joseph Yoder : Being Agile about Architecture
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Compiler
CompilerCompiler
Compiler
 
The Evolution of the Hadoop Ecosystem
The Evolution of the Hadoop EcosystemThe Evolution of the Hadoop Ecosystem
The Evolution of the Hadoop Ecosystem
 
Clean Code
Clean CodeClean Code
Clean Code
 
REST Problems
REST ProblemsREST Problems
REST Problems
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
Introdução ao Redis
Introdução ao RedisIntrodução ao Redis
Introdução ao Redis
 
Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...
Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...
Pesquisa e Ordenação - Aula 06 - Métodos de Ordenação (Intercalação - Merge s...
 
Mutexes, Monitores e Semáforos
Mutexes, Monitores e SemáforosMutexes, Monitores e Semáforos
Mutexes, Monitores e Semáforos
 
Design Pattern - Những công thức vàng trong thiết kế
Design Pattern - Những công thức vàng trong thiết kếDesign Pattern - Những công thức vàng trong thiết kế
Design Pattern - Những công thức vàng trong thiết kế
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
API Design and WebSocket
API Design and WebSocketAPI Design and WebSocket
API Design and WebSocket
 
CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly CNIT 126 6: Recognizing C Code Constructs in Assembly
CNIT 126 6: Recognizing C Code Constructs in Assembly
 
SOLID Design Principles applied in Java
SOLID Design Principles applied in JavaSOLID Design Principles applied in Java
SOLID Design Principles applied in Java
 
Embracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with FlywayEmbracing DevOps through database migrations with Flyway
Embracing DevOps through database migrations with Flyway
 
Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes Dynamic Binary Analysis and Obfuscated Codes
Dynamic Binary Analysis and Obfuscated Codes
 
Transforming to Microservices
Transforming to MicroservicesTransforming to Microservices
Transforming to Microservices
 

Similar to Programming language Ruby and the Rails framework

Graph databases & data integration - the case of RDF
Graph databases & data integration - the case of RDFGraph databases & data integration - the case of RDF
Graph databases & data integration - the case of RDFDimitris Kontokostas
 
Release webinar: Sansa and Ontario
Release webinar: Sansa and OntarioRelease webinar: Sansa and Ontario
Release webinar: Sansa and OntarioBigData_Europe
 
Knowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything ProjectKnowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything ProjectEnrico Daga
 
The SPARQL Anything project
The SPARQL Anything projectThe SPARQL Anything project
The SPARQL Anything projectEnrico Daga
 
Understanding the Standards Gap
Understanding the Standards GapUnderstanding the Standards Gap
Understanding the Standards GapDan Brickley
 
Ks2008 Semanticweb In Action
Ks2008 Semanticweb In ActionKs2008 Semanticweb In Action
Ks2008 Semanticweb In ActionRinke Hoekstra
 
Graph databases & data integration v2
Graph databases & data integration v2Graph databases & data integration v2
Graph databases & data integration v2Dimitris Kontokostas
 
Why Python?
Why Python?Why Python?
Why Python?Adam Pah
 
Applying large scale text analytics with graph databases
Applying large scale text analytics with graph databasesApplying large scale text analytics with graph databases
Applying large scale text analytics with graph databasesData Ninja API
 
MySQL 8.0 Document Store - Discovery of a New World
MySQL 8.0 Document Store - Discovery of a New WorldMySQL 8.0 Document Store - Discovery of a New World
MySQL 8.0 Document Store - Discovery of a New WorldFrederic Descamps
 
Ruby on Rails and the Semantic Web
Ruby on Rails and the Semantic WebRuby on Rails and the Semantic Web
Ruby on Rails and the Semantic WebNathalie Steinmetz
 
OO and Rails...
OO and Rails... OO and Rails...
OO and Rails... adzdavies
 
Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...
Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...
Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...datascienceiqss
 
Bentobox exercise by Rails Girls
Bentobox exercise by Rails Girls Bentobox exercise by Rails Girls
Bentobox exercise by Rails Girls Rails Girls Warsaw
 
06 gioca-ontologies
06 gioca-ontologies06 gioca-ontologies
06 gioca-ontologiesnidzokus
 
LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINE Corporation
 

Similar to Programming language Ruby and the Rails framework (20)

7-clean-code
7-clean-code7-clean-code
7-clean-code
 
Graph databases & data integration - the case of RDF
Graph databases & data integration - the case of RDFGraph databases & data integration - the case of RDF
Graph databases & data integration - the case of RDF
 
Release webinar: Sansa and Ontario
Release webinar: Sansa and OntarioRelease webinar: Sansa and Ontario
Release webinar: Sansa and Ontario
 
Knowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything ProjectKnowledge graph construction with a façade - The SPARQL Anything Project
Knowledge graph construction with a façade - The SPARQL Anything Project
 
The SPARQL Anything project
The SPARQL Anything projectThe SPARQL Anything project
The SPARQL Anything project
 
Understanding the Standards Gap
Understanding the Standards GapUnderstanding the Standards Gap
Understanding the Standards Gap
 
Ks2008 Semanticweb In Action
Ks2008 Semanticweb In ActionKs2008 Semanticweb In Action
Ks2008 Semanticweb In Action
 
Graph databases & data integration v2
Graph databases & data integration v2Graph databases & data integration v2
Graph databases & data integration v2
 
LabTech Introduction
LabTech IntroductionLabTech Introduction
LabTech Introduction
 
Why Python?
Why Python?Why Python?
Why Python?
 
Applying large scale text analytics with graph databases
Applying large scale text analytics with graph databasesApplying large scale text analytics with graph databases
Applying large scale text analytics with graph databases
 
MySQL 8.0 Document Store - Discovery of a New World
MySQL 8.0 Document Store - Discovery of a New WorldMySQL 8.0 Document Store - Discovery of a New World
MySQL 8.0 Document Store - Discovery of a New World
 
Ruby on Rails and the Semantic Web
Ruby on Rails and the Semantic WebRuby on Rails and the Semantic Web
Ruby on Rails and the Semantic Web
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
OO and Rails...
OO and Rails... OO and Rails...
OO and Rails...
 
Ruby
RubyRuby
Ruby
 
Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...
Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...
Data FAIRport Skunkworks: Common Repository Access Via Meta-Metadata Descript...
 
Bentobox exercise by Rails Girls
Bentobox exercise by Rails Girls Bentobox exercise by Rails Girls
Bentobox exercise by Rails Girls
 
06 gioca-ontologies
06 gioca-ontologies06 gioca-ontologies
06 gioca-ontologies
 
LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話LINEデリマでのElasticsearchの運用と監視の話
LINEデリマでのElasticsearchの運用と監視の話
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Programming language Ruby and the Rails framework

  • 1. Ruby programming language and Ruby on Rails framework
  • 2. Presentation Agenda  What is Ruby?  About the language  Its history  Principles of language  Code examples  Rails framework January 18, 2010 Radek Mika - Unicorn College 2
  • 3. What is Ruby?  Programming language  Interpreted language  Modern language  Object-oriented language  Dynamically typed language  Agile language January 18, 2010 Radek Mika - Unicorn College 3
  • 4. Principles of Ruby January 18, 2010 Radek Mika - Unicorn College 4
  • 5. Principles of Ruby January 18, 2010 Radek Mika - Unicorn College 5
  • 6. Principles of Ruby  Japanese Design  Focus on human factor  Principle of Least Surprise  Principle of Least Effort January 18, 2010 Radek Mika - Unicorn College 6
  • 7. The Principle of Least Surprise This principle is the supreme design goal of Ruby  It makes programmers happy  It makes Ruby easy to learn Examples  What class is an object? o.class  Is it Array.size or Array.length? same method - they are aliased  What are the differences between arrays? Diff = ary1 – ary2 Union = ary1 + ary2 January 18, 2010 Radek Mika - Unicorn College 7
  • 8. The Principle of Least Effort  We do not like to waste time Especially on XML configuration files, getters, setters, etc.  Syntactic sugar wherever you look  The quicker we program, the more we accomplish Sounds reasonable enough, does not it?  Less code means less bugs January 18, 2010 Radek Mika - Unicorn College 8
  • 9. Philosophy  No perfect language  Have joy  Computers are my servants, not my masters!  Unchangeable small core (syntax) and extensible class libraries January 18, 2010 Radek Mika - Unicorn College 9
  • 10. The History of Ruby  Created in Japan 10 years ago  Created by Yukihiro Matsumoto (known as Matz)  Inspired by Perl, Python, Lisp and Smalltalk January 18, 2010 Radek Mika - Unicorn College 10
  • 11. Comparison with Python  Interactive prompt (similar)  No special line terminator (similar)  Everything is an object (similar) X  More speed! (ruby is faster) … January 18, 2010 Radek Mika - Unicorn College 11
  • 12. Ruby is Truly Object-Oriented  Ruby uses single inheritance X  Mixins and Modules allow you to extend classes without multiple inheritance  Reflection  Things like ‘=’ and ‘+’ which may appear as operators are actually methods (like Smalltalk) January 18, 2010 Radek Mika - Unicorn College 12
  • 13. Well, that’s all nice but… …is it FAST? January 18, 2010 Radek Mika - Unicorn College 13
  • 14. Merge Sort Algorithm January 18, 2010 Radek Mika - Unicorn College 14
  • 15. Ruby Speed Comparison 3x faster than PHP 2.5x faster than Perl 2x faster than Python 2x (maybe more) C++ SLOWER than January 18, 2010 Radek Mika - Unicorn College 15
  • 16. Ruby Speed - WARNING Previous results are only informational (only Merge Sort Comparison) Another comparisons usually have different results January 18, 2010 Radek Mika - Unicorn College 16
  • 17. When I should not use Ruby?  If I need highly effective and powerful language, e.g. for distributed calculations  If I want to write a complicated, ugly or messy code Other disadvantages:  Less spread than Perl is  Ruby is relatively slow January 18, 2010 Radek Mika - Unicorn College 17
  • 18. And finally… …some code examples January 18, 2010 Radek Mika - Unicorn College 18
  • 19. Clear Syntax # Output "UPPER" puts "upper".upcase # Output the absolute value of -5: puts -5.abs # Output "Ruby Rocks!" 5 times 5.times do puts "Ruby Rocks!" end Source: http://pastie.org/785234 January 18, 2010 Radek Mika - Unicorn College 19
  • 20. Classes and Methods #Classes begin with class and end with end: # The Greeter class class Greeter end #Methods begin with def and end with end: # The salute method def salute end Source: http://pastie.org/785249 January 18, 2010 Radek Mika - Unicorn College 20
  • 21. Classes and Methods # The Greeter class class Greeter def initialize(greeting) @greeting = greeting end def salute(name) puts "#{@greeting} #{name}!" end end # Initialize our Greeter g = Greeter.new("Hello") # Output "Hello World!" g.salute("World") Source: http://pastie.org/785258 - classes January 18, 2010 Radek Mika - Unicorn College 21
  • 22. If Statements # if with several branches if account.total > 100000 puts "large account" elsif account.total > 25000 puts "medium account" else puts "small account„ end Sources: http://pastie.org/785268 January 18, 2010 Radek Mika - Unicorn College 22
  • 23. Case Statements # A simple case/when statement case name when "John" puts "Howdy John!" when "Ryan" puts "Whatz up Ryan!" else puts "Hi #{name}!" end Sources: http://pastie.org/785278 January 18, 2010 Radek Mika - Unicorn College 23
  • 24. Regular Expressions #Ruby supports Perl-style regular expressions: # Extract the parts of a phone number phone = "123-456-7890" if phone =~ /(d{3})-(d{3})-(d{4})/ ext = $1 city = $2 num = $3 end Sources: http://pastie.org/785732 January 18, 2010 Radek Mika - Unicorn College 24
  • 25. Regular Expressions # Case statement with regular expression case lang when /ruby/i puts "Matz created Ruby!" when /perl/i puts "Larry created Perl!" else puts "I don't know who created #{lang}." end Sources: http://pastie.org/785738 January 18, 2010 Radek Mika - Unicorn College 25
  • 26. Ruby Blocks # Print out a list of people from # each person in the Array people.each do |person| puts "* #{person.name}" end # A block using the bracket syntax 5.times { puts "Ruby rocks!" } # Custom sorting [2,1,3].sort! { |a, b| b <=> a } Sources: http://pastie.org/pastes/785239 January 18, 2010 Radek Mika - Unicorn College 26
  • 27. Yield to the Block! # define the thrice method def thrice yield yield yield end # Output "Blocks are cool!" three times thrice { puts "Blocks are cool!" } #This example use yield from within a method to #hand control over to a block: Sources: http://pastie.org/785774 January 18, 2010 Radek Mika - Unicorn College 27
  • 28. Blocks with Parameters # redefine the thrice method def thrice yield(1) yield(2) yield(3) end # Output "Blocks are cool!" three times, # prefix it with the count thrice { | i | puts "#{i}: Blocks are cool!" } Sources: http://pastie.org/785789 January 18, 2010 Radek Mika - Unicorn College 28
  • 29. Enough talking about Ruby!... What about Ruby on Rails? January 18, 2010 Radek Mika - Unicorn College 29
  • 30. Ruby on Rails  Web framework  An extremely productive web-application framework that is written in Ruby by David Hansson  Includes everything needed to create database-driven web applications according to the Model-View-Control pattern of separation  So-called reason of spreading ruby January 18, 2010 Radek Mika - Unicorn College 30
  • 31. Ruby on Rails  MVC  Convention over Configurations  Don’t Repeat Yourself (DRY) January 18, 2010 Radek Mika - Unicorn College 31
  • 32. History  Predominantly written by David H. Hannson  Talented designer  His dream is to change the world  A 37signals.com principal – World class designers  Since 2005 January 18, 2010 Radek Mika - Unicorn College 32
  • 33. Model – View - Controller  MVC is an architectural pattern, used not only for building web applications  Model classes are the "smart" domain objects (such as Account, Product, Person, Post) that hold business logic and know how to persist themselves to a database  Views are HTML templates  Controllers handle incoming requests (such as Save New Account, Update Product, Show Post) by manipulating the model and directing data to the view January 18, 2010 Radek Mika - Unicorn College 33
  • 34. Active Record Object/Relational Mapping Framework = Active Record  Automatic mapping between columns and class attributes  Declarative configuration via macros  Dynamic finders  Associations, Aggregations, Tree and List Behaviors  Locking  Lifecycle Callbacks  Single-table inheritance supported  Validation rules January 18, 2010 Radek Mika - Unicorn College 34
  • 35. From Controller to View Rails gives you many rendering options  Default template rendering Just follow naming conventions and magic happens.  Explicitly render to particular action  Redirect to another action  Render a string response (or no response) January 18, 2010 Radek Mika - Unicorn College 35
  • 36. View Template ERB –Embedded Ruby  Similar to JSPs <% and <%= syntax  Easy to learn and teach for designers  Execute in scope of controller  Denoted with .rhtml extension January 18, 2010 Radek Mika - Unicorn College 36
  • 37. View Template XmlMarkup –Programmatic View Construction  Great for writing xhtml and xml content  Denoted with .rxml extension  Embeddable in ERB templates January 18, 2010 Radek Mika - Unicorn College 37
  • 38. And Much More…  Templates and partials  Pagination  Caching (page, fragment, action)  Helpers  Routing with routes.rb  Exceptions  Unit testing  ActiveSupport API (date conversion, time calculations)  ActionMailer API  ActionWebService API  Rake January 18, 2010 Radek Mika - Unicorn College 38
  • 39. Sources  Ruby on Rails (Agile Atlanta Group) – Obie Fernandez – May 10 ’05  Ruby Language Overview – Muhamad Admin Rastgee  Ruby on Rails – Curt Hibbs  Workin’ on the Rails Road – Obie Fernandez  Get to the Point! (Development with Ruby on Rails) – Ryan Platte, John W. Long  Ruby speed comparison (http://is.gd/70hjD)  http://en.wikipedia.org/wiki/Ruby_on_Rails January 18, 2010 Radek Mika - Unicorn College 39
  • 40. External Links  http://ruby-lang.org – official website  http://www.ruby-doc.org/ - Ruby doc project  http://rubyforge.org/ - projects in Ruby  http://www.rubycentral.com/book/ - online book Programming Ruby  Full Ruby on Rails Tutorial  Euruko 2008 - videos from European Ruby Conference 2008 in Prague on avc- cvut.cz (Czech) January 18, 2010 Radek Mika - Unicorn College 40
  • 41. Between Q&A… … you can run this code … … do you still think that you have a fast computer? :) January 18, 2010 Radek Mika - Unicorn College 41
  • 42. Acknowledgments & Contact Special thanks to Mgr. Veronika Kaplanová for English correction. Radek Mika radek@radekmika.cz @radekmika (twitter) January 18, 2010 Radek Mika - Unicorn College 42
  • 43. January 18, 2010 Radek Mika - Unicorn College 43