SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
happy 20th birthday!
                                           seesaw
lunedì 4 marzo 13
Yukihiro Matsumoto
                      matz
                        osaka
                    april 14, 1965




                                     seesaw
lunedì 4 marzo 13
“I	 always	 thought	 Smalltalk	 would	 beat	 Java.I	 just	 didn’t	 
                           know	 if	 would	 be	 called	 ‘Ruby’	 when	 it	 did	 so”

                                                                        -	 Kent	 Beck	 -




                                                                                           seesaw
lunedì 4 marzo 13
The Ruby Language
                    •   Designed for programmer productivity and fun

                    •   Generic, interpreted, reflective, with garbage collection

                    •   Optimized for people rather than computers

                    •   More powerful than Perl, more object oriented than Python

                    •   Everything is an object. There are no primitive types

                    •   Strong dynamic typing



                                                                                    seesaw
lunedì 4 marzo 13
implementations
                    •   Matz's Ruby Interpreter or MRI, uses its own Ruby-specific virtual machine
                        written in C

                    •   JRuby, runs on the Java virtual machine

                    •   Rubinius, C++ bytecode VM that uses LLVM to compile to machine code at
                        runtime

                    •   MagLev, a Smalltalk implementation

                    •   MacRuby, an OS X implementation on the Objective-C runtime

                    •   IronRuby, an implementation on the .NET Framework

                                                                                                    seesaw
lunedì 4 marzo 13
versions
                    v0.95 - December 21, 1995
                     v1.0 - December 25, 1996
                       v1.2 - December 1998
                           v1.3 - year1999
                         v1.4 - August 1999
                      v1.6 - September 2000
                         v1.8 - August 2003
                        Ruby on Rails - 2005
                       v1.9 - December 2007


                                                seesaw
lunedì 4 marzo 13
Everything in Ruby is


                    ‣ Assignment - binding names to objects
                    ‣ Control structures - if/else, while, case
                    ‣ Sending messages to objects - methods


                                                                  seesaw
lunedì 4 marzo 13
irb

                          seesaw
lunedì 4 marzo 13
strings

                    a   =   "nThis is a double-quoted stringn"
                    a   =   %Q{nThis is a double-quoted stringn}
                    a   =   %{nThis is a double-quoted stringn}
                    a   =   %/nThis is a double-quoted stringn/
                    a   =   <<-BLOCK

                    This is a double-quoted string
                    BLOCK

                    a = 'This is a single-quoted string'
                    a = %q{This is a single-quoted string}




                                                                     seesaw
lunedì 4 marzo 13
collections

                    a = [1, 'hi', 3.14, 1, 2, [4, 5]]

                    puts   a[2]             #   3.14
                    puts   a.[](2)          #   3.14
                    puts   a.reverse        #   [[4, 5], 2, 1, 3.14, 'hi', 1]
                    puts   a.flatten.uniq   #   [1, 'hi', 3.14, 2, 4, 5]




                                                                                seesaw
lunedì 4 marzo 13
associative arrays
                    hash   = Hash.new
                    hash   = { :water => 'wet', :fire => 'hot' }
                    puts   hash[:fire]
                    # =>   hot

                    hash.each do |key, value|
                      puts "#{key} is #{value}"
                    end
                    # => water is wet
                    #    fire is hot

                    hash.delete :water
                    # Deletes water: 'wet'
                    hash.delete_if { |key,value| value == 'hot'}
                    # Deletes :fire => 'hot'




                                                                   seesaw
lunedì 4 marzo 13
blocks & iterators

                      do
                        puts "Hello, World!"
                      end



                                 oppure

                      { puts "Hello, World!" }




                                                 seesaw
lunedì 4 marzo 13
closures
                    # In an object instance variable (denoted with '@'),
                    remember a block.
                    def remember(&a_block)
                      @block = a_block
                    end

                    # Invoke the above method, giving it a block which takes a
                    name.
                    remember {|name| puts "Hello, #{name}!"}

                    # When the time is right (for the object) -- call the
                    closure!
                    @block.call("Jon")
                    # => "Hello, Jon!"




                                                                                 seesaw
lunedì 4 marzo 13
closures
             def create_set_and_get(initial_value=0) # Note the default value of 0
               closure_value = initial_value
               return Proc.new {|x| closure_value = x}, Proc.new { closure_value }
             end

             setter, getter = create_set_and_get   # ie. returns two values
             setter.call(21)
             getter.call # => 21




                                                                                     seesaw
lunedì 4 marzo 13
closures
             def create_set_and_get(initial_value=0) # Note the default value of 0
               closure_value = initial_value
               return Proc.new {|x| closure_value = x}, Proc.new { closure_value }
             end

             setter, getter = create_set_and_get   # ie. returns two values
             setter.call(21)
             getter.call # => 21

             #You can also use a parameter variable as a binding for the closure.
             #So the above can be rewritten as...

             def create_set_and_get(closure_value=0)
                return proc {|x| closure_value = x } , proc { closure_value }
             en




                                                                                     seesaw
lunedì 4 marzo 13
yield

                    def use_hello
                      yield "hello"
                    end

                    # Invoke the above method, passing it a block.
                    use_hello {|string| puts string} # => 'hello'




                                                                     seesaw
lunedì 4 marzo 13
enumeration
                    array = [1, 'hi', 3.14]
                    array.each {|item| puts item }
                    # => 1
                    # => 'hi'
                    # => 3.14

                    array.each_index do|index|
                      puts "#{index}: #{array[index]}"
                    end
                    # => 0: 1
                    # => 1: 'hi'
                    # => 2: 3.14

                    # The following uses a Range
                    (3..6).each {|num| puts num }
                    # => 3
                    # => 4
                    # => 5
                    # => 6


                                                         seesaw
lunedì 4 marzo 13
functional programming
                    [1,3,5].inject(10) {|sum, element| sum + element}
                    # => 19

                    File.open('file.txt', 'w') do |file|
                      # 'w' denotes "write mode"
                      file.puts 'Wrote some text.'
                    end # File is automatically closed here

                    File.readlines('file.txt').each do |line|
                      puts line
                    end


                    (1..10).collect {|x| x*x}
                    # => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
                    (1..5).collect(&:to_f)
                    # => [1.0, 2.0, 3.0, 4.0, 5.0]

                                                                        seesaw
lunedì 4 marzo 13
classes
                    class Person
                      attr_reader :name, :age
                      def initialize(name, age)
                        @name, @age = name, age
                      end
                      def <=>(person) # Comparison operator for sorting
                        age <=> person.age
                      end
                      def to_s
                        "#{name} (#{age})"
                      end
                    end

                    group = [
                      Person.new("Bob", 33),
                      Person.new("Chris", 16),
                      Person.new("Ash", 23)
                    ]

                    puts group.sort.reverse

                                                                          seesaw
lunedì 4 marzo 13
monkey patching

                    # re-open Ruby's Time class
                    class Time
                      def yesterday
                        self - 86400
                      end
                    end

                    today = Time.now
                    # => Thu Aug 14 16:51:50 +1200 2012
                    yesterday = today.yesterday
                    # => Wed Aug 13 16:51:50 +1200 2012




                                                          seesaw
lunedì 4 marzo 13
metaprogramming
                    COLORS = { black:     "000",
                               red:       "f00",
                               green:     "0f0",
                               yellow:    "ff0",
                               blue:      "00f",
                               magenta:   "f0f",
                               cyan:      "0ff",
                               white:     "fff" }

                    class String
                      COLORS.each do |color,code|
                        define_method "in_#{color}" do
                          "<span style="color: ##{code}">#{self}</span>"
                        end
                      end
                    end



                                                                             seesaw
lunedì 4 marzo 13
2.0
                    fully backward compatible with Ruby 1.9.3




                                                                seesaw
lunedì 4 marzo 13
default source encoding is UTF-8



                                                       seesaw
lunedì 4 marzo 13
require improvements
                                           seesaw
lunedì 4 marzo 13
GC is copy-on-write friendly



                                                   seesaw
lunedì 4 marzo 13
Fine-Grained Asynchronous
                         Interrupt Handling




                                                seesaw
lunedì 4 marzo 13
D-Trace support



                                      seesaw
lunedì 4 marzo 13
keyword arguments
                        def render(source, opts = {})
                          opts = {fmt: 'html'}.merge(opts)
                          r = Renderer.for(opts[:fmt])
                    1.9   r.render(source)
                        end

                       render(template, fmt: 'json')




                        def render(source, fmt: 'html')
                          r = Renderer.for(fmt)
                          r.render(source)
                    2.0 end

                        render(template, fmt: 'json')


                                                             seesaw
lunedì 4 marzo 13
1.9




                    problems are on method definition




                                                       seesaw
lunedì 4 marzo 13
Caller side doesn't change




                                                 seesaw
lunedì 4 marzo 13
lazy enumerables




                                       seesaw
lunedì 4 marzo 13
lazy enumerables




                                       seesaw
lunedì 4 marzo 13
lazy enumerables
                    def natural_numbers
                      (1..Float::INFINITY).lazy
                    end

                    def primes
                      natural_numbers.select {|n|
                        (2..(n**0.5)).all? {|f|
                          n % f > 0
                        }
                      }
                    end

                    primes.take(10).force
                    #=> [1, 2, 3, 5, 7, 11, 13, 17, 19, 23]




                                                              seesaw
lunedì 4 marzo 13
Module Prepending




                                        seesaw
lunedì 4 marzo 13
Module Prepending




                                        seesaw
lunedì 4 marzo 13
Module Prepending




                      no more alias method chain
                                                   seesaw
lunedì 4 marzo 13
:ruby and so.why?(‘not’)




                                               seesaw
lunedì 4 marzo 13
:ruby and so.why?(‘not’)




                                               seesaw
lunedì 4 marzo 13
http://www.ruby-lang.org/




                                                seesaw
lunedì 4 marzo 13
http://www.ruby-doc.org/




                                               seesaw
lunedì 4 marzo 13
http://modulecounts.com/




                                               seesaw
lunedì 4 marzo 13
http://www.rubygems.org/




                                               seesaw
lunedì 4 marzo 13
seesaw
lunedì 4 marzo 13
questions?

                                 seesaw
lunedì 4 marzo 13
!anks.

                         @fuzziness
                     michele@franzin.net
                                           seesaw
lunedì 4 marzo 13
http://en.wikipedia.org/wiki/Ruby_(programming_language)




                                                  credits
                                  http://benhoskin.gs/2013/02/24/ruby-2-0-by-example


                               http://benhoskin.gs/2013/02/24/getting-to-know-ruby-2-0


                             https://speakerdeck.com/shyouhei/whats-new-in-ruby-2-dot-0


                    http://www.slideshare.net/peter_marklund/ruby-on-rails-101-presentation-slides-
                                         for-a-five-day-introductory-course


lunedì 4 marzo 13

Weitere ähnliche Inhalte

Ähnlich wie Ruby 20th birthday

De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresNorman Clarke
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming IntroductionAnthony Brown
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationWorkhorse Computing
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Wen-Tien Chang
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressionsplarsen67
 
Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Bozhidar Batsov
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to heroDiego Lemos
 
How and why you should test
How and why you should testHow and why you should test
How and why you should testPuppet
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012xSawyer
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement SauvageCocoaHeads France
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends旻琦 潘
 
Enterprise javascriptsession3
Enterprise javascriptsession3Enterprise javascriptsession3
Enterprise javascriptsession3Troy Miles
 
Rspec group
Rspec groupRspec group
Rspec groupthefonso
 

Ähnlich wie Ruby 20th birthday (20)

De vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored proceduresDe vuelta al pasado con SQL y stored procedures
De vuelta al pasado con SQL y stored procedures
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
Bash and regular expressions
Bash and regular expressionsBash and regular expressions
Bash and regular expressions
 
Ruby
RubyRuby
Ruby
 
Ruby 101
Ruby 101Ruby 101
Ruby 101
 
Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)Модерни езици за програмиране за JVM (2011)
Модерни езици за програмиране за JVM (2011)
 
Ruby from zero to hero
Ruby from zero to heroRuby from zero to hero
Ruby from zero to hero
 
How and why you should test
How and why you should testHow and why you should test
How and why you should test
 
Immutability
ImmutabilityImmutability
Immutability
 
Script it
Script itScript it
Script it
 
Babushka
BabushkaBabushka
Babushka
 
Moose - YAPC::NA 2012
Moose - YAPC::NA 2012Moose - YAPC::NA 2012
Moose - YAPC::NA 2012
 
Realm.io par Clement Sauvage
Realm.io par Clement SauvageRealm.io par Clement Sauvage
Realm.io par Clement Sauvage
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
Einführung in Node.js
Einführung in Node.jsEinführung in Node.js
Einführung in Node.js
 
Enterprise javascriptsession3
Enterprise javascriptsession3Enterprise javascriptsession3
Enterprise javascriptsession3
 
Rspec group
Rspec groupRspec group
Rspec group
 
Introducing Ruby
Introducing RubyIntroducing Ruby
Introducing Ruby
 

Mehr von michele franzin

Trasformare un'applicazione monolitica in microservices (versione #daje)
Trasformare un'applicazione monolitica in microservices (versione #daje)Trasformare un'applicazione monolitica in microservices (versione #daje)
Trasformare un'applicazione monolitica in microservices (versione #daje)michele franzin
 
Come ti smantello un'app monolitica in microservices
Come ti smantello un'app monolitica in microservicesCome ti smantello un'app monolitica in microservices
Come ti smantello un'app monolitica in microservicesmichele franzin
 
Microservices: cosa sono e quando non usarli
Microservices: cosa sono e quando non usarliMicroservices: cosa sono e quando non usarli
Microservices: cosa sono e quando non usarlimichele franzin
 
from(0).to('rubygems.org')
from(0).to('rubygems.org')from(0).to('rubygems.org')
from(0).to('rubygems.org')michele franzin
 

Mehr von michele franzin (6)

Unleashing git power
Unleashing git powerUnleashing git power
Unleashing git power
 
Trasformare un'applicazione monolitica in microservices (versione #daje)
Trasformare un'applicazione monolitica in microservices (versione #daje)Trasformare un'applicazione monolitica in microservices (versione #daje)
Trasformare un'applicazione monolitica in microservices (versione #daje)
 
Come ti smantello un'app monolitica in microservices
Come ti smantello un'app monolitica in microservicesCome ti smantello un'app monolitica in microservices
Come ti smantello un'app monolitica in microservices
 
Microservices: cosa sono e quando non usarli
Microservices: cosa sono e quando non usarliMicroservices: cosa sono e quando non usarli
Microservices: cosa sono e quando non usarli
 
Magie di git
Magie di gitMagie di git
Magie di git
 
from(0).to('rubygems.org')
from(0).to('rubygems.org')from(0).to('rubygems.org')
from(0).to('rubygems.org')
 

Kürzlich hochgeladen

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

Ruby 20th birthday

  • 1. happy 20th birthday! seesaw lunedì 4 marzo 13
  • 2. Yukihiro Matsumoto matz osaka april 14, 1965 seesaw lunedì 4 marzo 13
  • 3. “I always thought Smalltalk would beat Java.I just didn’t know if would be called ‘Ruby’ when it did so” - Kent Beck - seesaw lunedì 4 marzo 13
  • 4. The Ruby Language • Designed for programmer productivity and fun • Generic, interpreted, reflective, with garbage collection • Optimized for people rather than computers • More powerful than Perl, more object oriented than Python • Everything is an object. There are no primitive types • Strong dynamic typing seesaw lunedì 4 marzo 13
  • 5. implementations • Matz's Ruby Interpreter or MRI, uses its own Ruby-specific virtual machine written in C • JRuby, runs on the Java virtual machine • Rubinius, C++ bytecode VM that uses LLVM to compile to machine code at runtime • MagLev, a Smalltalk implementation • MacRuby, an OS X implementation on the Objective-C runtime • IronRuby, an implementation on the .NET Framework seesaw lunedì 4 marzo 13
  • 6. versions v0.95 - December 21, 1995 v1.0 - December 25, 1996 v1.2 - December 1998 v1.3 - year1999 v1.4 - August 1999 v1.6 - September 2000 v1.8 - August 2003 Ruby on Rails - 2005 v1.9 - December 2007 seesaw lunedì 4 marzo 13
  • 7. Everything in Ruby is ‣ Assignment - binding names to objects ‣ Control structures - if/else, while, case ‣ Sending messages to objects - methods seesaw lunedì 4 marzo 13
  • 8. irb seesaw lunedì 4 marzo 13
  • 9. strings a = "nThis is a double-quoted stringn" a = %Q{nThis is a double-quoted stringn} a = %{nThis is a double-quoted stringn} a = %/nThis is a double-quoted stringn/ a = <<-BLOCK This is a double-quoted string BLOCK a = 'This is a single-quoted string' a = %q{This is a single-quoted string} seesaw lunedì 4 marzo 13
  • 10. collections a = [1, 'hi', 3.14, 1, 2, [4, 5]] puts a[2] # 3.14 puts a.[](2) # 3.14 puts a.reverse # [[4, 5], 2, 1, 3.14, 'hi', 1] puts a.flatten.uniq # [1, 'hi', 3.14, 2, 4, 5] seesaw lunedì 4 marzo 13
  • 11. associative arrays hash = Hash.new hash = { :water => 'wet', :fire => 'hot' } puts hash[:fire] # => hot hash.each do |key, value| puts "#{key} is #{value}" end # => water is wet # fire is hot hash.delete :water # Deletes water: 'wet' hash.delete_if { |key,value| value == 'hot'} # Deletes :fire => 'hot' seesaw lunedì 4 marzo 13
  • 12. blocks & iterators do puts "Hello, World!" end oppure { puts "Hello, World!" } seesaw lunedì 4 marzo 13
  • 13. closures # In an object instance variable (denoted with '@'), remember a block. def remember(&a_block) @block = a_block end # Invoke the above method, giving it a block which takes a name. remember {|name| puts "Hello, #{name}!"} # When the time is right (for the object) -- call the closure! @block.call("Jon") # => "Hello, Jon!" seesaw lunedì 4 marzo 13
  • 14. closures def create_set_and_get(initial_value=0) # Note the default value of 0 closure_value = initial_value return Proc.new {|x| closure_value = x}, Proc.new { closure_value } end setter, getter = create_set_and_get # ie. returns two values setter.call(21) getter.call # => 21 seesaw lunedì 4 marzo 13
  • 15. closures def create_set_and_get(initial_value=0) # Note the default value of 0 closure_value = initial_value return Proc.new {|x| closure_value = x}, Proc.new { closure_value } end setter, getter = create_set_and_get # ie. returns two values setter.call(21) getter.call # => 21 #You can also use a parameter variable as a binding for the closure. #So the above can be rewritten as... def create_set_and_get(closure_value=0) return proc {|x| closure_value = x } , proc { closure_value } en seesaw lunedì 4 marzo 13
  • 16. yield def use_hello yield "hello" end # Invoke the above method, passing it a block. use_hello {|string| puts string} # => 'hello' seesaw lunedì 4 marzo 13
  • 17. enumeration array = [1, 'hi', 3.14] array.each {|item| puts item } # => 1 # => 'hi' # => 3.14 array.each_index do|index| puts "#{index}: #{array[index]}" end # => 0: 1 # => 1: 'hi' # => 2: 3.14 # The following uses a Range (3..6).each {|num| puts num } # => 3 # => 4 # => 5 # => 6 seesaw lunedì 4 marzo 13
  • 18. functional programming [1,3,5].inject(10) {|sum, element| sum + element} # => 19 File.open('file.txt', 'w') do |file| # 'w' denotes "write mode" file.puts 'Wrote some text.' end # File is automatically closed here File.readlines('file.txt').each do |line| puts line end (1..10).collect {|x| x*x} # => [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] (1..5).collect(&:to_f) # => [1.0, 2.0, 3.0, 4.0, 5.0] seesaw lunedì 4 marzo 13
  • 19. classes class Person attr_reader :name, :age def initialize(name, age) @name, @age = name, age end def <=>(person) # Comparison operator for sorting age <=> person.age end def to_s "#{name} (#{age})" end end group = [ Person.new("Bob", 33), Person.new("Chris", 16), Person.new("Ash", 23) ] puts group.sort.reverse seesaw lunedì 4 marzo 13
  • 20. monkey patching # re-open Ruby's Time class class Time def yesterday self - 86400 end end today = Time.now # => Thu Aug 14 16:51:50 +1200 2012 yesterday = today.yesterday # => Wed Aug 13 16:51:50 +1200 2012 seesaw lunedì 4 marzo 13
  • 21. metaprogramming COLORS = { black: "000", red: "f00", green: "0f0", yellow: "ff0", blue: "00f", magenta: "f0f", cyan: "0ff", white: "fff" } class String COLORS.each do |color,code| define_method "in_#{color}" do "<span style="color: ##{code}">#{self}</span>" end end end seesaw lunedì 4 marzo 13
  • 22. 2.0 fully backward compatible with Ruby 1.9.3 seesaw lunedì 4 marzo 13
  • 23. default source encoding is UTF-8 seesaw lunedì 4 marzo 13
  • 24. require improvements seesaw lunedì 4 marzo 13
  • 25. GC is copy-on-write friendly seesaw lunedì 4 marzo 13
  • 26. Fine-Grained Asynchronous Interrupt Handling seesaw lunedì 4 marzo 13
  • 27. D-Trace support seesaw lunedì 4 marzo 13
  • 28. keyword arguments def render(source, opts = {}) opts = {fmt: 'html'}.merge(opts) r = Renderer.for(opts[:fmt]) 1.9 r.render(source) end render(template, fmt: 'json') def render(source, fmt: 'html') r = Renderer.for(fmt) r.render(source) 2.0 end render(template, fmt: 'json') seesaw lunedì 4 marzo 13
  • 29. 1.9 problems are on method definition seesaw lunedì 4 marzo 13
  • 30. Caller side doesn't change seesaw lunedì 4 marzo 13
  • 31. lazy enumerables seesaw lunedì 4 marzo 13
  • 32. lazy enumerables seesaw lunedì 4 marzo 13
  • 33. lazy enumerables def natural_numbers (1..Float::INFINITY).lazy end def primes natural_numbers.select {|n| (2..(n**0.5)).all? {|f| n % f > 0 } } end primes.take(10).force #=> [1, 2, 3, 5, 7, 11, 13, 17, 19, 23] seesaw lunedì 4 marzo 13
  • 34. Module Prepending seesaw lunedì 4 marzo 13
  • 35. Module Prepending seesaw lunedì 4 marzo 13
  • 36. Module Prepending no more alias method chain seesaw lunedì 4 marzo 13
  • 37. :ruby and so.why?(‘not’) seesaw lunedì 4 marzo 13
  • 38. :ruby and so.why?(‘not’) seesaw lunedì 4 marzo 13
  • 39. http://www.ruby-lang.org/ seesaw lunedì 4 marzo 13
  • 40. http://www.ruby-doc.org/ seesaw lunedì 4 marzo 13
  • 41. http://modulecounts.com/ seesaw lunedì 4 marzo 13
  • 42. http://www.rubygems.org/ seesaw lunedì 4 marzo 13
  • 44. questions? seesaw lunedì 4 marzo 13
  • 45. !anks. @fuzziness michele@franzin.net seesaw lunedì 4 marzo 13
  • 46. http://en.wikipedia.org/wiki/Ruby_(programming_language) credits http://benhoskin.gs/2013/02/24/ruby-2-0-by-example http://benhoskin.gs/2013/02/24/getting-to-know-ruby-2-0 https://speakerdeck.com/shyouhei/whats-new-in-ruby-2-dot-0 http://www.slideshare.net/peter_marklund/ruby-on-rails-101-presentation-slides- for-a-five-day-introductory-course lunedì 4 marzo 13