SlideShare una empresa de Scribd logo
1 de 44
Descargar para leer sin conexión
The  Joy  of  
Ruby

        Clinton  R.  Nixon,  Viget  Labs
Ruby  is  designed  to  
 make  programmers  
         happy.  
–  Yukihiro  Matsumoto
Simplicity
a = "hello world"

class String
  def no_vowels
    self.gsub(/[aeiou]/, '')
  end
end

p a.no_vowels # "hll wrld"



          Openness
Natural  Language
        case   year
        when   1800...1900 then "19th century"
        when   1900...2000 then "20th century"
        else   "21st century"
        end

        "word".include? "a"

        5.times do
          paint.stir!
        end

        color "orange blossom" do
          red 224
          yellow 147
          blue 22
        end
An  IntroducDon  to  Ruby
The  Ruby  Language
Object-oriented               Imperative




  Functional                  Dynamic



                  Reflective
Basic  Types
Integer (Fixnum, Bignum) 8192

Float                   3.14159

String                  "3.14159"

Symbol                  :corndog

Array                   ["gala", "fuji"]

Hash                    {:plums => 2, :pears => 7}

Boolean                 false
Object-­‐Oriented

1.8.class # Float

Array.new(["a", "b", "c"]) # ["a", "b",
"c"]

true.is_a?(Object) # true
true.class # TrueClass
true.methods # ["==", "===",
"instance_eval", "freeze", "to_a",
Modules,  Classes,  and  Objects
module Authentication
  def valid_api_keys
    Database.retrieve_all_keys
  end

  def authenticated?(api_key)
    valid_api_keys.include?
api_key
  end
end

class PublicAPI
  include Authentication

  def initialize(api_key)
    @api_key = api_key
  end

  def act
    if authenticated?(@api_key)
      do_a_thing
    end
  end
end
Inheritance
class PrivateAPI                  end
  include Authentication
                                class PublicAPI
  def initialize(id, api_key)     include Authentication
     @client = DB.get_client
(id)                              def act
     @api_key = api_key             if authenticated?(@api_key)
  end                                 do_a_thing
                                    end
  def valid_api_keys              end
    @client.api_keys            end
  end
                                class NewAPI < PublicAPI
  def act                         def act
    if authenticated?               if authenticated?(@api_key)
(@api_key)                            do_a_new_thing
      @client.do_a_thing            end
    end                           end
  end                           end
The  Inheritance  Chain

           superclass


Self   Class     Modules
Dynamic  &  Duck  Typing

               It’s not what type of
               object you have
               It’s what that object
               can do
Duck  Typing  in  AcDon
class Rectangle < Struct.new(:width, :height)
  include Comparable

  def <=>(other)
    (self.width * self.height) <=>
      (other.width * other.height)
  end
end

r1 = Rectangle.new(4, 10)
r2 = Rectangle.new(5, 7)

r1 > r2 # => false
FuncDonal
Ruby has broad support
for functional
programming

But it’s not a functional
language

You could say it’s
pragmatically functional
Blocks
numbers = (1..10)
numbers.map { |n| n * n }
# => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
numbers.reduce { |total, n| total += n }
# => 55

odd_test = proc { |n| n % 2 == 1 }
numbers.select(&odd_test)
# => [1, 3, 5, 7, 9]

def before_save(&block)
  @before_callbacks << block
end
First-­‐class  FuncDons
def counter(x = 0)
  proc { x += 1 }
end

next_num = counter
next_num.call # =>   1
next_num.call # =>   2
next_num.call # =>   3
next_num.call # =>   4

another_seq = counter(10)
another_seq.call # => 11
First-­‐class  FuncDons
def is_prime?(x)
  is_prime = proc do |n, m|
    if m > (n / 2)
      true
    elsif n % m == 0
      false
    else
      is_prime.call(n, m + 1)
    end
  end

  is_prime.call(x, 2) if x >= 2
end

(1..23).select { |n| is_prime?(n) }
# => [2, 3, 5, 7, 11, 13, 17, 19, 23]
ReflecDon

Struct.new
(:AC, :THAC0).new.local_methods
# => ["AC", "AC=", "THAC0", "THAC0=",
#     "[]", "[]=", "all?", "any?", ...]

a = Rational(1, 2)

a.instance_variables
# => ["@denominator", "@numerator"]

a.instance_variable_get("@numerator")
# => 1
Metaprogramming

module Accessors
  def access(var)
    define_method(var) do
      instance_variable_get("@#{var}")
    end

    define_method("#{var}=") do |val|
      instance_variable_set("@#{var}",
         val)
    end
  end
end
Metaprogramming
        class Monster
          extend Accessors
          access :damage

          def initialize(damage)
            @damage = damage
          end
        end

        wampa = Monster.new("2d6")
        wampa.damage # => "2d6"
        wampa.damage = "1d12"
The  Ruby  Ecosystem
Rails,  Rack,  
and  Passenger
Merb
Sinatra
Ramaze
Waves
others




          Other  Web  Frameworks
Web  deployment
set :application, 'listy'
set :repository, "git@github.com:viget/listyapp.git"
set :scm, 'git'

role :web, "listyapp.com"
role :app, "listyapp.com"
role :db, "listyapp.com", :primary => true

set :user, "listy"
set :deploy_to, "/home/listy/rails"
RubyGems

     Standard package
     management tool

     More like apt than CPAN

     Included with Ruby 1.9
Open  Source
The Ruby License is much
like the MIT License.

Most Ruby gems are under
the Ruby license or MIT
License.

GitHub is the hub of most
Ruby OS activity.
Other  ImplementaDons
       JRuby
     IronRuby
     MacRuby
     and others
Ruby  Shared  Values
TesDng
Rails was the first
framework I used that
came with testing built in.

Community has exploded
in the last few years with
testing tools.

It’s rare I see a project
without tests.
ConvenDon  over  ConfiguraDon


“The three chief virtues of a programmer are:
Laziness, Impatience and Hubris.”
– Larry Wall, who is not a Ruby programmer
Version  Control
Everyone should use version control, so this
isn’t really a value.
But Ruby programmers are fanatics for their
VCS.
Git is the VCS of choice.
Being distributed, it allows for easy public forks
of projects, which has helped OS in Ruby.
Sharing
   Ruby programmers have been
   chastised as self-promoters. I
   don’t see that as a bad thing.

   We share everything: open
   source code, discoveries, tips
   and tricks.

   Talk, talk, talk

   Blog, blog, blog
Passion

I don’t know any
Ruby programmers
who aren’t excited
about programming.
Why  Ruby  Was  Right  For  Us
(and  Might  Be  Right  For  You)
O"en  people,  especially  computer  engineers,  
focus  on  the  machines.  They  think,  "By  doing  
this,  the  machine  will  run  faster.  By  doing  this,  
the  machine  will  run  more  effec>vely.  ..."  They  
are  focusing  on  machines.  But  in  fact  we  need  
to  focus  on  humans,  on  how  humans  care  
about  doing  programming  or  opera>ng  the  
applica>on  of  the  machines.
                                                  –  Matz


TranslaDon:  Ruby  is  not  so  fast.
ProducDvity
     Conventions and dynamism
     speed development.

     There are ridiculous quotes
     about “3-10x.”

     Personal observation: as a
     project goes on, it doesn’t get
     any harder, unlike other
     languages.

     Will testing slow you down?
Morale

Anecdotally: people like to
program in Ruby.

Productive people are
happier.

Seeing instant results is
very rewarding.
Broad  UDlity
Text processing
Cross-platform GUI development: Monkeybars,
Limelight, and Shoes
Server configuration management: Chef, Puppet, and
Sprinkle
Web servers: Mongrel, Unicorn, and Thin
Testing other languages
and anything else that isn’t matheletic
PlaYorm  AgnosDc
MRI runs on Windows, OS X, Linux, and most
other Unixes.
JRuby runs anywhere Java will run.
IronRuby is going to make .NET awesome.
Passenger works with Apache.
But you can proxy through or use FastCGI from
any web server, even IIS.
QuesDons

Más contenido relacionado

La actualidad más candente

JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7Codemotion
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentationManav Prasad
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To ClosureRobert Nyman
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOSJorge Ortiz
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)jaxLondonConference
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Codemotion
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)James Titcumb
 
Elegant Solutions For Everyday Python Problems - Nina Zakharenko
Elegant Solutions For Everyday Python Problems - Nina ZakharenkoElegant Solutions For Everyday Python Problems - Nina Zakharenko
Elegant Solutions For Everyday Python Problems - Nina ZakharenkoNina Zakharenko
 
Elixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsElixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsBrooklyn Zelenka
 
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...Codemotion
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the futureAnsviaLab
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends旻琦 潘
 

La actualidad más candente (20)

JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
 
Kotlin
KotlinKotlin
Kotlin
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
JavaScript - From Birth To Closure
JavaScript - From Birth To ClosureJavaScript - From Birth To Closure
JavaScript - From Birth To Closure
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS7 Stages of Unit Testing in iOS
7 Stages of Unit Testing in iOS
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)What You Need to Know About Lambdas - Jamie Allen (Typesafe)
What You Need to Know About Lambdas - Jamie Allen (Typesafe)
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 
Elegant Solutions For Everyday Python Problems - Nina Zakharenko
Elegant Solutions For Everyday Python Problems - Nina ZakharenkoElegant Solutions For Everyday Python Problems - Nina Zakharenko
Elegant Solutions For Everyday Python Problems - Nina Zakharenko
 
Elixir and Phoenix for Rubyists
Elixir and Phoenix for RubyistsElixir and Phoenix for Rubyists
Elixir and Phoenix for Rubyists
 
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 

Similar a The Joy of Ruby in 40 Characters

Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Mark Menard
 
Ruby new wheels_condensed
Ruby new wheels_condensedRuby new wheels_condensed
Ruby new wheels_condensedosake
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testersPaolo Perego
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of JavascriptSamuel Abraham
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2
name name2 n2name name2 n2
name name2 n2callroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n
name name2 nname name2 n
name name2 ncallroom
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.pptcallroom
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmersamiable_indian
 

Similar a The Joy of Ruby in 40 Characters (20)

Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Ruby new wheels_condensed
Ruby new wheels_condensedRuby new wheels_condensed
Ruby new wheels_condensed
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testers
 
обзор Python
обзор Pythonобзор Python
обзор Python
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
Dutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: DistilledDutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: Distilled
 
ppt7
ppt7ppt7
ppt7
 
ppt2
ppt2ppt2
ppt2
 
name name2 n
name name2 nname name2 n
name name2 n
 
name name2 n2
name name2 n2name name2 n2
name name2 n2
 
test ppt
test ppttest ppt
test ppt
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt21
ppt21ppt21
ppt21
 
name name2 n
name name2 nname name2 n
name name2 n
 
ppt17
ppt17ppt17
ppt17
 
ppt30
ppt30ppt30
ppt30
 
name name2 n2.ppt
name name2 n2.pptname name2 n2.ppt
name name2 n2.ppt
 
ppt18
ppt18ppt18
ppt18
 
Ruby for Perl Programmers
Ruby for Perl ProgrammersRuby for Perl Programmers
Ruby for Perl Programmers
 

Más de Clinton Dreisbach

Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Clinton Dreisbach
 
Narwhal and the Adventures of CommonJS
Narwhal and the Adventures of CommonJSNarwhal and the Adventures of CommonJS
Narwhal and the Adventures of CommonJSClinton Dreisbach
 
Unearthed Arcana for Web People
Unearthed Arcana for Web PeopleUnearthed Arcana for Web People
Unearthed Arcana for Web PeopleClinton Dreisbach
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with RailsClinton Dreisbach
 
Dealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsDealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsClinton Dreisbach
 

Más de Clinton Dreisbach (7)

Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Narwhal and the Adventures of CommonJS
Narwhal and the Adventures of CommonJSNarwhal and the Adventures of CommonJS
Narwhal and the Adventures of CommonJS
 
HTML5 Now
HTML5 NowHTML5 Now
HTML5 Now
 
Unearthed Arcana for Web People
Unearthed Arcana for Web PeopleUnearthed Arcana for Web People
Unearthed Arcana for Web People
 
Advanced Internationalization with Rails
Advanced Internationalization with RailsAdvanced Internationalization with Rails
Advanced Internationalization with Rails
 
Dealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsDealing with Legacy PHP Applications
Dealing with Legacy PHP Applications
 

Último

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
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
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
[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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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
 
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
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 

Último (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
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
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
[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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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
 
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
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 

The Joy of Ruby in 40 Characters

  • 1. The  Joy  of   Ruby Clinton  R.  Nixon,  Viget  Labs
  • 2. Ruby  is  designed  to   make  programmers   happy.   –  Yukihiro  Matsumoto
  • 4. a = "hello world" class String def no_vowels self.gsub(/[aeiou]/, '') end end p a.no_vowels # "hll wrld" Openness
  • 5. Natural  Language case year when 1800...1900 then "19th century" when 1900...2000 then "20th century" else "21st century" end "word".include? "a" 5.times do paint.stir! end color "orange blossom" do red 224 yellow 147 blue 22 end
  • 7. The  Ruby  Language Object-oriented Imperative Functional Dynamic Reflective
  • 8.
  • 9. Basic  Types Integer (Fixnum, Bignum) 8192 Float 3.14159 String "3.14159" Symbol :corndog Array ["gala", "fuji"] Hash {:plums => 2, :pears => 7} Boolean false
  • 10. Object-­‐Oriented 1.8.class # Float Array.new(["a", "b", "c"]) # ["a", "b", "c"] true.is_a?(Object) # true true.class # TrueClass true.methods # ["==", "===", "instance_eval", "freeze", "to_a",
  • 11. Modules,  Classes,  and  Objects module Authentication def valid_api_keys Database.retrieve_all_keys end def authenticated?(api_key) valid_api_keys.include? api_key end end class PublicAPI include Authentication def initialize(api_key) @api_key = api_key end def act if authenticated?(@api_key) do_a_thing end end end
  • 12. Inheritance class PrivateAPI end include Authentication class PublicAPI def initialize(id, api_key) include Authentication @client = DB.get_client (id) def act @api_key = api_key if authenticated?(@api_key) end do_a_thing end def valid_api_keys end @client.api_keys end end class NewAPI < PublicAPI def act def act if authenticated? if authenticated?(@api_key) (@api_key) do_a_new_thing @client.do_a_thing end end end end end
  • 13. The  Inheritance  Chain superclass Self Class Modules
  • 14. Dynamic  &  Duck  Typing It’s not what type of object you have It’s what that object can do
  • 15. Duck  Typing  in  AcDon class Rectangle < Struct.new(:width, :height) include Comparable def <=>(other) (self.width * self.height) <=> (other.width * other.height) end end r1 = Rectangle.new(4, 10) r2 = Rectangle.new(5, 7) r1 > r2 # => false
  • 16. FuncDonal Ruby has broad support for functional programming But it’s not a functional language You could say it’s pragmatically functional
  • 17. Blocks numbers = (1..10) numbers.map { |n| n * n } # => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] numbers.reduce { |total, n| total += n } # => 55 odd_test = proc { |n| n % 2 == 1 } numbers.select(&odd_test) # => [1, 3, 5, 7, 9] def before_save(&block) @before_callbacks << block end
  • 18. First-­‐class  FuncDons def counter(x = 0) proc { x += 1 } end next_num = counter next_num.call # => 1 next_num.call # => 2 next_num.call # => 3 next_num.call # => 4 another_seq = counter(10) another_seq.call # => 11
  • 19. First-­‐class  FuncDons def is_prime?(x) is_prime = proc do |n, m| if m > (n / 2) true elsif n % m == 0 false else is_prime.call(n, m + 1) end end is_prime.call(x, 2) if x >= 2 end (1..23).select { |n| is_prime?(n) } # => [2, 3, 5, 7, 11, 13, 17, 19, 23]
  • 20. ReflecDon Struct.new (:AC, :THAC0).new.local_methods # => ["AC", "AC=", "THAC0", "THAC0=", # "[]", "[]=", "all?", "any?", ...] a = Rational(1, 2) a.instance_variables # => ["@denominator", "@numerator"] a.instance_variable_get("@numerator") # => 1
  • 21. Metaprogramming module Accessors def access(var) define_method(var) do instance_variable_get("@#{var}") end define_method("#{var}=") do |val| instance_variable_set("@#{var}", val) end end end
  • 22. Metaprogramming class Monster extend Accessors access :damage def initialize(damage) @damage = damage end end wampa = Monster.new("2d6") wampa.damage # => "2d6" wampa.damage = "1d12"
  • 24.
  • 25. Rails,  Rack,   and  Passenger
  • 26. Merb Sinatra Ramaze Waves others Other  Web  Frameworks
  • 27. Web  deployment set :application, 'listy' set :repository, "git@github.com:viget/listyapp.git" set :scm, 'git' role :web, "listyapp.com" role :app, "listyapp.com" role :db, "listyapp.com", :primary => true set :user, "listy" set :deploy_to, "/home/listy/rails"
  • 28. RubyGems Standard package management tool More like apt than CPAN Included with Ruby 1.9
  • 29. Open  Source The Ruby License is much like the MIT License. Most Ruby gems are under the Ruby license or MIT License. GitHub is the hub of most Ruby OS activity.
  • 30. Other  ImplementaDons JRuby IronRuby MacRuby and others
  • 32.
  • 33. TesDng Rails was the first framework I used that came with testing built in. Community has exploded in the last few years with testing tools. It’s rare I see a project without tests.
  • 34. ConvenDon  over  ConfiguraDon “The three chief virtues of a programmer are: Laziness, Impatience and Hubris.” – Larry Wall, who is not a Ruby programmer
  • 35. Version  Control Everyone should use version control, so this isn’t really a value. But Ruby programmers are fanatics for their VCS. Git is the VCS of choice. Being distributed, it allows for easy public forks of projects, which has helped OS in Ruby.
  • 36. Sharing Ruby programmers have been chastised as self-promoters. I don’t see that as a bad thing. We share everything: open source code, discoveries, tips and tricks. Talk, talk, talk Blog, blog, blog
  • 37. Passion I don’t know any Ruby programmers who aren’t excited about programming.
  • 38. Why  Ruby  Was  Right  For  Us (and  Might  Be  Right  For  You)
  • 39. O"en  people,  especially  computer  engineers,   focus  on  the  machines.  They  think,  "By  doing   this,  the  machine  will  run  faster.  By  doing  this,   the  machine  will  run  more  effec>vely.  ..."  They   are  focusing  on  machines.  But  in  fact  we  need   to  focus  on  humans,  on  how  humans  care   about  doing  programming  or  opera>ng  the   applica>on  of  the  machines. –  Matz TranslaDon:  Ruby  is  not  so  fast.
  • 40. ProducDvity Conventions and dynamism speed development. There are ridiculous quotes about “3-10x.” Personal observation: as a project goes on, it doesn’t get any harder, unlike other languages. Will testing slow you down?
  • 41. Morale Anecdotally: people like to program in Ruby. Productive people are happier. Seeing instant results is very rewarding.
  • 42. Broad  UDlity Text processing Cross-platform GUI development: Monkeybars, Limelight, and Shoes Server configuration management: Chef, Puppet, and Sprinkle Web servers: Mongrel, Unicorn, and Thin Testing other languages and anything else that isn’t matheletic
  • 43. PlaYorm  AgnosDc MRI runs on Windows, OS X, Linux, and most other Unixes. JRuby runs anywhere Java will run. IronRuby is going to make .NET awesome. Passenger works with Apache. But you can proxy through or use FastCGI from any web server, even IIS.