SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Ruby
       para programadores PHP




Monday, April 25, 2011
PHP

       História

       • Criada por Rasmus Lerdorf em 1994.


       • Objetivo: Fazer um contador para a página pessoal de Rasmus.


       • Originalmente era apenas uma biblioteca Perl.


       • PHP3 escrito por Andi Gutmans e Zeev Suraski (Zend) em 1997/98




Monday, April 25, 2011
Ruby

       História

       • Criada por Yukihiro Matsumoto (Matz) em 1993.


       • Objetivo: Criar uma linguagem poderosa que tenha uma “versão simplificada”
         de programação funcional com ótima OO.


       • Matz: “I wanted a scripting language that was more powerful than Perl, and
         more object-oriented than Python. That's why I decided to design my own
         language”


       • Matz: “I hope to see Ruby help every programmer in the world to be
         productive, and to enjoy programming, and to be happy. That is the primary
         purpose of Ruby language.”


Monday, April 25, 2011
PHP

       Variáveis

       $number = 18;
       $string = “John”;
       $bool = true;
       $array = array(7,8,6,5);
       $hash = array(“foo” => “bar”);
       $obj = new Class(“param”);




Monday, April 25, 2011
Ruby

       Variáveis

       number = 18
       string = “John”
       another_string = %(The man said “Wow”)
       bool = true
       array = [7,8,6,5];
       word_array = %w{hello ruby world}
       hash = {:foo => ‘bar’} # new_hash = {foo:‘bar’}
       obj = Class.new(“param”)

       # news!

       ages = 18..45 # range
       cep = /^d{5}-d{3}$/ # regular expression


Monday, April 25, 2011
PHP

       Paradigma

       • Procedural com suporte a OO.


       $a = array(1,2,3);
       array_shift($a);
       => 1
       array_pop($a);
       => 3
       array_push($a, 4);
       => [2,4]




Monday, April 25, 2011
Ruby

       Paradigma

       • Procedural, totalmente OO com classes (Smalltalk-like), um tanto funcional
         com o conceito de blocos. Not Haskell thought.

       a = [1,2,3]
       a.shift
       => 1
       a.pop
       => 3
       a.push(4)
       => [2,4]




Monday, April 25, 2011
PHP

       Tipagem

       • Dinâmica e fraca.

       10 + “10”;
       => 20




Monday, April 25, 2011
Ruby

       Tipagem

       • Dinâmica e forte. (Aberta a mudanças.)

       10 + “10”
       => TypeError: String can't be coerced into Fixnum

       class Fixnum
         alias :old_sum :+
         def + s
           old_sum s.to_i
         end
       end
       10 + “10”
       => 20

Monday, April 25, 2011
Ruby

       Tipagem

       • ...como???

       1 + 1
       => 2

       1.+(1)
       => 2

       1.send(‘+’, 1)
       => 2

       # “Operações”? Métodos!



Monday, April 25, 2011
PHP

       Fluxo

       • if, switch, ternário;

       if($i == $j){ ... }

       $i == $j ? ... : ...

       switch($i){
         case(“valor”){
           TODO
         }
       }




Monday, April 25, 2011
Ruby

       Fluxo

       • if, unless ...

       if i == j
         ...
       end

       unless cond
         ...
       end

       puts “Maior” if age >= 18

       puts “Menor” unless user.adult?

Monday, April 25, 2011
Ruby

       Fluxo

       • ...case...

       # default usage
       case hour
         when 1: ...
         when 2: ...
       end

       # with ranges!
       case hour
         when 0..7, 19..23: puts “Good nite”
         when 8..12: puts “Good mornin’”
       end

Monday, April 25, 2011
Ruby

       Fluxo

       • ...case...

       # with regexes
       case date
         when /d{2}-d{2}-d{4}/: ...
         when /d{2}/d{2}/d{4}/: ...
       end

       # crie seu próprio case
       class MyClass
         def ===
           ...
         end
       end
Monday, April 25, 2011
PHP

       Iteradores

       • while, for, foreach;

       while($i < 10){ ... }

       for($i = 0; $i < length($clients); $i++){ ... }

       foreach($clients as $client){ ... }




Monday, April 25, 2011
Ruby

       Iteradores

       • for in, each, map, select, inject... enumeradores;

       5.times{ ... }

       [5,7,4].each{ ... }

       [1,2,3].map{|i| i + 1 }
       => [2,3,4]

       [16,19,22].select{|i| i >= 18 }
       => [19,22]

       [5,7,8].inject{|s,i| s + i }
       => 20
Monday, April 25, 2011
Ruby

       Iteradores / Blocos

       • crie seu próprio iterador:

       def hi_five
         yield 1; yield 2; yield 3; yield 4; yield 5
       end

       hi_five{|i| ... }




Monday, April 25, 2011
Ruby

       Blocos

       • power to the people.

       File.open(“file”, “w”){|f| f.write(“Wow”) }

       File.each_line(“file”){|l| ... }

       Dir.glob(“*.png”){ ... }

       “Ruby para programadores PHP”.gsub(/PHP/){|m| ... }

       get “/” { ... } # sinatra

       p{ span “Ruby is ”; strong “cool”   } # markaby

Monday, April 25, 2011
PHP

       OO

       • Herança comum, classes abstratas, interfaces. Como Java.




Monday, April 25, 2011
Ruby

       OO

       • Classes e módulos.

       module Walker
         def walk
           ...
         end
       end

       # módulo como “herança múltipla” ou “mixin”
       class Johny
         include Walker
       end



Monday, April 25, 2011
Ruby

       OO

       • Classes e módulos.

       # módulo como “namescope”
       module Foo
         class Bar
           ...
         end
       end



       variable = Foo::Bar.new




Monday, April 25, 2011
PHP

       OO Dinâmico

       • __call: Chama métodos não existentes.


       • __get: Chama “atributos” não existentes.


       • __set: Chama ao tentar setar atributos não existentes;


       $obj->metodo();

       $obj->atributo;

       $obj->atributo = “valor”;



Monday, April 25, 2011
Ruby

       OO Dinâmico

       • method_missing: Tudo em Ruby são chamadas de métodos.

       obj.metodo # chama o método “metodo”

       obj.atributo # chama o método “atributo”

       obj.atributo = “valor” # chama o método “atributo=”

       class Foo
         def method_missing m, *args
           ...
         end
       end

Monday, April 25, 2011
Ruby

       OO Dinâmico

       • inherited...

       # inherited
       class Foo
         def self.inherited(subklass)
           ...
         end
       end

       class Bar < Foo
       end




Monday, April 25, 2011
Ruby

       OO Dinâmico

       • included...

       # included
       module Foo
         def included(klass)
           ...
         end
       end

       class Bar
         include Foo
       end



Monday, April 25, 2011
Ruby

       OO Dinâmico

       • class_eval, class_exec....

       class Foo; end

       Foo.class_eval(“def bar() ... end”)
       Foo.class_exec{ def bar() ... end }

       Foo.bar # works
       Foo.baz # works




Monday, April 25, 2011
Ruby

       OO Dinâmico

       • instance_eval, instance_exec, define_method....

       class Foo
         define_method(:bar) { ... }
         instance_exec{ def baz(); ... end }
         instance_eval(“def qux(); ... end”)
       end



       Foo.new.bar # works
       Foo.new.baz # works
       Foo.new.qux # works



Monday, April 25, 2011
Ruby

       OO Dinâmico

       • attr_(reader|accessor|writer)

       class Foo
         attr_accessor :bar
       end

       # same as...
       class Foo
         def bar() @bar end
         def bar= val
           @bar = val
         end
       end

Monday, April 25, 2011
Ruby

       OO Dinâmico

       • nesting, alias, autoload, class_variable_(set|get|defined?), const_(get|set|
         defined?|missing), constanst, instance_(method|methods), method_(added|
         defined?|removed|undefined), remove_(class_variable|const|method),
         undef_method, and so much more...




Monday, April 25, 2011
PHP

       Comunidade

       • PECL, PEAR. ... PHP Classes?




Monday, April 25, 2011
Ruby

       Comunidade

       • RubyGems

       gem install bundler # install gem

       bundler gem my_gem # create my own gem

       cd my_gem

       rake release # that’s all folks

       #also
       bundler install # install all dependencies for a project



Monday, April 25, 2011
Ruby

       Comunidade

       • GitHub




Monday, April 25, 2011
Monday, April 25, 2011

Contenu connexe

En vedette

Ruby para-programadores-php
Ruby para-programadores-phpRuby para-programadores-php
Ruby para-programadores-phpJuan Maiz
 
rails_and_agile
rails_and_agilerails_and_agile
rails_and_agileJuan Maiz
 
Ruby para programadores PHP
Ruby para programadores PHPRuby para programadores PHP
Ruby para programadores PHPJuan Maiz
 
Reasoning about Code with React
Reasoning about Code with ReactReasoning about Code with React
Reasoning about Code with ReactJuan Maiz
 
SaaS - RubyMastersConf.com.br
SaaS - RubyMastersConf.com.brSaaS - RubyMastersConf.com.br
SaaS - RubyMastersConf.com.brJuan Maiz
 

En vedette (7)

Ruby para-programadores-php
Ruby para-programadores-phpRuby para-programadores-php
Ruby para-programadores-php
 
rails_and_agile
rails_and_agilerails_and_agile
rails_and_agile
 
Tree top
Tree topTree top
Tree top
 
Ruby para programadores PHP
Ruby para programadores PHPRuby para programadores PHP
Ruby para programadores PHP
 
Reasoning about Code with React
Reasoning about Code with ReactReasoning about Code with React
Reasoning about Code with React
 
SaaS - RubyMastersConf.com.br
SaaS - RubyMastersConf.com.brSaaS - RubyMastersConf.com.br
SaaS - RubyMastersConf.com.br
 
Saas
SaasSaas
Saas
 

Similaire à Ruby para-programadores-php

Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introductionGonçalo Silva
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9sagaroceanic11
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9sagaroceanic11
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Henry S
 
Ruby an overall approach
Ruby an overall approachRuby an overall approach
Ruby an overall approachFelipe Schmitt
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Mark Menard
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to RubyMark Menard
 
Rails for PHP Developers
Rails for PHP DevelopersRails for PHP Developers
Rails for PHP DevelopersRobert Dempsey
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueJames Thompson
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Michelangelo van Dam
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Rormyuser
 
06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptxThắng It
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010ssoroka
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011tobiascrawley
 
Test First Teaching
Test First TeachingTest First Teaching
Test First TeachingSarah Allen
 

Similaire à Ruby para-programadores-php (20)

Ruby — An introduction
Ruby — An introductionRuby — An introduction
Ruby — An introduction
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
 
Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9Rubyforjavaprogrammers 1210167973516759-9
Rubyforjavaprogrammers 1210167973516759-9
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Ruby an overall approach
Ruby an overall approachRuby an overall approach
Ruby an overall approach
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
 
Rails for PHP Developers
Rails for PHP DevelopersRails for PHP Developers
Rails for PHP Developers
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
 
Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010Php Crash Course - Macq Electronique 2010
Php Crash Course - Macq Electronique 2010
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Perl 101
Perl 101Perl 101
Perl 101
 
06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011Torquebox @ Charlotte.rb May 2011
Torquebox @ Charlotte.rb May 2011
 
Test First Teaching
Test First TeachingTest First Teaching
Test First Teaching
 
Ruby
RubyRuby
Ruby
 

Dernier

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Dernier (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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 Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Ruby para-programadores-php

  • 1. Ruby para programadores PHP Monday, April 25, 2011
  • 2. PHP História • Criada por Rasmus Lerdorf em 1994. • Objetivo: Fazer um contador para a página pessoal de Rasmus. • Originalmente era apenas uma biblioteca Perl. • PHP3 escrito por Andi Gutmans e Zeev Suraski (Zend) em 1997/98 Monday, April 25, 2011
  • 3. Ruby História • Criada por Yukihiro Matsumoto (Matz) em 1993. • Objetivo: Criar uma linguagem poderosa que tenha uma “versão simplificada” de programação funcional com ótima OO. • Matz: “I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language” • Matz: “I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language.” Monday, April 25, 2011
  • 4. PHP Variáveis $number = 18; $string = “John”; $bool = true; $array = array(7,8,6,5); $hash = array(“foo” => “bar”); $obj = new Class(“param”); Monday, April 25, 2011
  • 5. Ruby Variáveis number = 18 string = “John” another_string = %(The man said “Wow”) bool = true array = [7,8,6,5]; word_array = %w{hello ruby world} hash = {:foo => ‘bar’} # new_hash = {foo:‘bar’} obj = Class.new(“param”) # news! ages = 18..45 # range cep = /^d{5}-d{3}$/ # regular expression Monday, April 25, 2011
  • 6. PHP Paradigma • Procedural com suporte a OO. $a = array(1,2,3); array_shift($a); => 1 array_pop($a); => 3 array_push($a, 4); => [2,4] Monday, April 25, 2011
  • 7. Ruby Paradigma • Procedural, totalmente OO com classes (Smalltalk-like), um tanto funcional com o conceito de blocos. Not Haskell thought. a = [1,2,3] a.shift => 1 a.pop => 3 a.push(4) => [2,4] Monday, April 25, 2011
  • 8. PHP Tipagem • Dinâmica e fraca. 10 + “10”; => 20 Monday, April 25, 2011
  • 9. Ruby Tipagem • Dinâmica e forte. (Aberta a mudanças.) 10 + “10” => TypeError: String can't be coerced into Fixnum class Fixnum alias :old_sum :+ def + s old_sum s.to_i end end 10 + “10” => 20 Monday, April 25, 2011
  • 10. Ruby Tipagem • ...como??? 1 + 1 => 2 1.+(1) => 2 1.send(‘+’, 1) => 2 # “Operações”? Métodos! Monday, April 25, 2011
  • 11. PHP Fluxo • if, switch, ternário; if($i == $j){ ... } $i == $j ? ... : ... switch($i){ case(“valor”){ TODO } } Monday, April 25, 2011
  • 12. Ruby Fluxo • if, unless ... if i == j ... end unless cond ... end puts “Maior” if age >= 18 puts “Menor” unless user.adult? Monday, April 25, 2011
  • 13. Ruby Fluxo • ...case... # default usage case hour when 1: ... when 2: ... end # with ranges! case hour when 0..7, 19..23: puts “Good nite” when 8..12: puts “Good mornin’” end Monday, April 25, 2011
  • 14. Ruby Fluxo • ...case... # with regexes case date when /d{2}-d{2}-d{4}/: ... when /d{2}/d{2}/d{4}/: ... end # crie seu próprio case class MyClass def === ... end end Monday, April 25, 2011
  • 15. PHP Iteradores • while, for, foreach; while($i < 10){ ... } for($i = 0; $i < length($clients); $i++){ ... } foreach($clients as $client){ ... } Monday, April 25, 2011
  • 16. Ruby Iteradores • for in, each, map, select, inject... enumeradores; 5.times{ ... } [5,7,4].each{ ... } [1,2,3].map{|i| i + 1 } => [2,3,4] [16,19,22].select{|i| i >= 18 } => [19,22] [5,7,8].inject{|s,i| s + i } => 20 Monday, April 25, 2011
  • 17. Ruby Iteradores / Blocos • crie seu próprio iterador: def hi_five yield 1; yield 2; yield 3; yield 4; yield 5 end hi_five{|i| ... } Monday, April 25, 2011
  • 18. Ruby Blocos • power to the people. File.open(“file”, “w”){|f| f.write(“Wow”) } File.each_line(“file”){|l| ... } Dir.glob(“*.png”){ ... } “Ruby para programadores PHP”.gsub(/PHP/){|m| ... } get “/” { ... } # sinatra p{ span “Ruby is ”; strong “cool” } # markaby Monday, April 25, 2011
  • 19. PHP OO • Herança comum, classes abstratas, interfaces. Como Java. Monday, April 25, 2011
  • 20. Ruby OO • Classes e módulos. module Walker def walk ... end end # módulo como “herança múltipla” ou “mixin” class Johny include Walker end Monday, April 25, 2011
  • 21. Ruby OO • Classes e módulos. # módulo como “namescope” module Foo class Bar ... end end variable = Foo::Bar.new Monday, April 25, 2011
  • 22. PHP OO Dinâmico • __call: Chama métodos não existentes. • __get: Chama “atributos” não existentes. • __set: Chama ao tentar setar atributos não existentes; $obj->metodo(); $obj->atributo; $obj->atributo = “valor”; Monday, April 25, 2011
  • 23. Ruby OO Dinâmico • method_missing: Tudo em Ruby são chamadas de métodos. obj.metodo # chama o método “metodo” obj.atributo # chama o método “atributo” obj.atributo = “valor” # chama o método “atributo=” class Foo def method_missing m, *args ... end end Monday, April 25, 2011
  • 24. Ruby OO Dinâmico • inherited... # inherited class Foo def self.inherited(subklass) ... end end class Bar < Foo end Monday, April 25, 2011
  • 25. Ruby OO Dinâmico • included... # included module Foo def included(klass) ... end end class Bar include Foo end Monday, April 25, 2011
  • 26. Ruby OO Dinâmico • class_eval, class_exec.... class Foo; end Foo.class_eval(“def bar() ... end”) Foo.class_exec{ def bar() ... end } Foo.bar # works Foo.baz # works Monday, April 25, 2011
  • 27. Ruby OO Dinâmico • instance_eval, instance_exec, define_method.... class Foo define_method(:bar) { ... } instance_exec{ def baz(); ... end } instance_eval(“def qux(); ... end”) end Foo.new.bar # works Foo.new.baz # works Foo.new.qux # works Monday, April 25, 2011
  • 28. Ruby OO Dinâmico • attr_(reader|accessor|writer) class Foo attr_accessor :bar end # same as... class Foo def bar() @bar end def bar= val @bar = val end end Monday, April 25, 2011
  • 29. Ruby OO Dinâmico • nesting, alias, autoload, class_variable_(set|get|defined?), const_(get|set| defined?|missing), constanst, instance_(method|methods), method_(added| defined?|removed|undefined), remove_(class_variable|const|method), undef_method, and so much more... Monday, April 25, 2011
  • 30. PHP Comunidade • PECL, PEAR. ... PHP Classes? Monday, April 25, 2011
  • 31. Ruby Comunidade • RubyGems gem install bundler # install gem bundler gem my_gem # create my own gem cd my_gem rake release # that’s all folks #also bundler install # install all dependencies for a project Monday, April 25, 2011
  • 32. Ruby Comunidade • GitHub Monday, April 25, 2011