SlideShare uma empresa Scribd logo
1 de 55
A ciência por trás
     do Ruby
               Carlos Brando
         www.nomedojogo.com
BETA

A ciência por trás
     do Ruby
               Carlos Brando
         www.nomedojogo.com
BEGIN
  WHILE 1=1 DO
    BEGIN
      outtext("Hello World!");
      outimage;
    END;
END;
Simula
template<typename _Tp, typename _Sequence = deque<_Tp> >
    class stack
    {
      // concept requirements
      typedef typename _Sequence::value_type _Sequence_value_type;
      __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
      __glibcxx_class_requires(_Sequence, _BackInsertionSequenceConcept)
      __glibcxx_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept)

    }
template<typename _Tp, typename _Sequence = deque<_Tp> >
    class stack
    {
      // concept requirements
      typedef typename _Sequence::value_type _Sequence_value_type;
      __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
      __glibcxx_class_requires(_Sequence, _BackInsertionSequenceConcept)
      __glibcxx_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept)

    }




   final class Pair<A extends Comparable<A> & Cloneable<A>,
                    B extends Comparable<B> & Cloneable<B>>
      implements Comparable<Pair<A,B>>, Cloneable<Pair<A,B>> {



   }
http://blog.caelum.com.br/2006/10/14/como-nao-aprender-orientacao-a-objetos-heranca/
Ruby
 é uma linguagem
orientada a objetos
Ruby
 é uma verdadeira
     linguagem
orientada a objetos
Objetos
Estado + Comportamento
class Dog
  def initialize(breed, name)
    @breed = breed
    @name = name
  end

  def eat
    # ...
  end

  def sleep
    # ...
  end
end
rex = Dog.new("bulldog", "Rex")
rex = Dog.new("bulldog", "Rex")



      rex
@breed: “bulldog”
@name: “Rex”

sleep()
eat()
rex = Dog.new("bulldog", "Rex")



                                   Dog
     rex
@breed                     sleep
@name
                           eat
tabela de métodos
rex = Dog.new("bulldog", "Rex")



                                   Dog
        rex
@breed                     sleep
@name
                           eat
class
fido = Dog.new("vira-lata", "Fido")

        fido
@breed                              Dog
@name
class                       sleep
                            eat

        rex
@breed
@name
class
self
self
      É o centro do seu código Ruby


• Onde as variáveis de instância são encontradas
Ex: @var

• O receiver padrão para as chamadas de métodos
Ex: eat(‘hot dog’)
self
Apenas duas coisas podem mudar self


• Uma chamada de método
• A definição de uma classe/módulo
dog = "rex"

puts dog.upcase

puts dog.object_id

def dog.speak
  "Auau"
end

puts dog.speak
self           String
dog   @value: “rex”   downcase
                      upcase
      class
Object
                      dup
                      object_id

                      parent




          self            String
dog   @value: “rex”   downcase
                      upcase
      class
                      parent
Object
                      dup
                      object_id

                      parent

                          String
                      downcase
                      upcase

                      parent
          self
                           ????
dog   @value: “rex”
                      speak
      class

                      parent
Object
     Singleton Class
                                  dup
                                  object_id
• Eigenclass, Metaclass,
Ghost Class, Virtual Class, ...   parent


• Uma classe comum, mas               String
escondida                         downcase
                                  upcase
• Apenas uma por objeto
                                  parent
                    self
                                       ????
  dog           @value: “rex”
                                  speak
                class

                                  parent
self
Apenas duas coisas podem mudar self


  Uma chamada de método

• A definição de uma classe/módulo
# código

class Dog

  # código

end

# código
class Dog

  def speak
   “Miau”
  end

  def self.speak
    "Auau"
  end

end
Object
                     dup
                     object_id

                     parent




          self          Dog
                     parent
dog   @name: “rex”   metodos

      class
Object      Object
                     dup         dup
                     object_id   object_id

                     parent      parent




          self          Dog         Class
                     parent      parent
dog   @name: “rex”   metodos

      class
                     class       class
Object

                       Object
                      dup           Class
                      object_id   parent

                      parent
                                  class


          self           Dog         ????
                      parent      parent
dog   @value: “rex”   metodos
                                  speak
      class
                      class
Tudo que você precisa se
      lembrar é...


 Variáveis de instância: localizadas na variável self

 Métodos: localizados na classe da variável self
Mas ainda não
terminamos...
class Dog

  class << self
    def speak
    end
  end

end
public class Cachorro {
  private static int patas = "";

    public static int getPatas() {
      return patas;
    }
}
class Cachorro
  @patas = 4

  def getPatas
    @patas
  end
end
Mas ainda não
terminamos...
class B < A

end
Só mais uma coisa
   importante...
include
   vs
extend
Object
dup
object_id

parent




 Minha Classe
parent
downcase
upcase
Object
dup
object_id



   ????         MeuMódulo
parent
                metodo
   tabela de
   métodos


  MinhaClasse
parent
meu_metodo
Tudo isso fez sentido
    para você?
@carlosbrando

Mais conteúdo relacionado

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

A ciência por trás do Ruby

  • 1. A ciência por trás do Ruby Carlos Brando www.nomedojogo.com
  • 2. BETA A ciência por trás do Ruby Carlos Brando www.nomedojogo.com
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. BEGIN WHILE 1=1 DO BEGIN outtext("Hello World!"); outimage; END; END;
  • 12.
  • 13.
  • 14.
  • 15. template<typename _Tp, typename _Sequence = deque<_Tp> > class stack { // concept requirements typedef typename _Sequence::value_type _Sequence_value_type; __glibcxx_class_requires(_Tp, _SGIAssignableConcept) __glibcxx_class_requires(_Sequence, _BackInsertionSequenceConcept) __glibcxx_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept) }
  • 16. template<typename _Tp, typename _Sequence = deque<_Tp> > class stack { // concept requirements typedef typename _Sequence::value_type _Sequence_value_type; __glibcxx_class_requires(_Tp, _SGIAssignableConcept) __glibcxx_class_requires(_Sequence, _BackInsertionSequenceConcept) __glibcxx_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept) } final class Pair<A extends Comparable<A> & Cloneable<A>, B extends Comparable<B> & Cloneable<B>> implements Comparable<Pair<A,B>>, Cloneable<Pair<A,B>> { }
  • 18. Ruby é uma linguagem orientada a objetos
  • 19. Ruby é uma verdadeira linguagem orientada a objetos
  • 21.
  • 22. class Dog def initialize(breed, name) @breed = breed @name = name end def eat # ... end def sleep # ... end end
  • 24. rex = Dog.new("bulldog", "Rex") rex @breed: “bulldog” @name: “Rex” sleep() eat()
  • 25. rex = Dog.new("bulldog", "Rex") Dog rex @breed sleep @name eat tabela de métodos
  • 26. rex = Dog.new("bulldog", "Rex") Dog rex @breed sleep @name eat class
  • 27. fido = Dog.new("vira-lata", "Fido") fido @breed Dog @name class sleep eat rex @breed @name class
  • 28. self
  • 29. self É o centro do seu código Ruby • Onde as variáveis de instância são encontradas Ex: @var • O receiver padrão para as chamadas de métodos Ex: eat(‘hot dog’)
  • 30. self Apenas duas coisas podem mudar self • Uma chamada de método • A definição de uma classe/módulo
  • 31. dog = "rex" puts dog.upcase puts dog.object_id def dog.speak "Auau" end puts dog.speak
  • 32. self String dog @value: “rex” downcase upcase class
  • 33. Object dup object_id parent self String dog @value: “rex” downcase upcase class parent
  • 34. Object dup object_id parent String downcase upcase parent self ???? dog @value: “rex” speak class parent
  • 35. Object Singleton Class dup object_id • Eigenclass, Metaclass, Ghost Class, Virtual Class, ... parent • Uma classe comum, mas String escondida downcase upcase • Apenas uma por objeto parent self ???? dog @value: “rex” speak class parent
  • 36. self Apenas duas coisas podem mudar self Uma chamada de método • A definição de uma classe/módulo
  • 37. # código class Dog # código end # código
  • 38. class Dog def speak “Miau” end def self.speak "Auau" end end
  • 39. Object dup object_id parent self Dog parent dog @name: “rex” metodos class
  • 40. Object Object dup dup object_id object_id parent parent self Dog Class parent parent dog @name: “rex” metodos class class class
  • 41. Object Object dup Class object_id parent parent class self Dog ???? parent parent dog @value: “rex” metodos speak class class
  • 42. Tudo que você precisa se lembrar é... Variáveis de instância: localizadas na variável self Métodos: localizados na classe da variável self
  • 44. class Dog class << self def speak end end end
  • 45. public class Cachorro { private static int patas = ""; public static int getPatas() { return patas; } }
  • 46. class Cachorro @patas = 4 def getPatas @patas end end
  • 48. class B < A end
  • 49. Só mais uma coisa importante...
  • 50. include vs extend
  • 52. Object dup object_id ???? MeuMódulo parent metodo tabela de métodos MinhaClasse parent meu_metodo
  • 53. Tudo isso fez sentido para você?
  • 54.

Notas do Editor