SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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')
 

Dernier

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
🐬 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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
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
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
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
 
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
 
[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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Dernier (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
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
 
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...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
[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
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

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