GithubHelp home page GithubHelp logo

mod-1-discussion-questions-object-orientation-in-ruby's Introduction

Week 1, Day 2 Morning Discussion Questions

Instructions

Take 30 minutes and answer the following questions together with your group. Take turns playing around with the code provided in Pry or IRB.

Questions

1 . If the Animal class is defined like this:

class Animal

  def species
    "cat"
  end

end

How would you:

  1. Make a new instance of `Animal`?
  2. `puts` out to the terminal, the species of that new `Animal` instance?

2 . Although we all know that cats are the best species, not all animals are cats (unfortunately). How could you change the Animal class so that an instance of animal can have its species set to any species at all?

3 . We have the following class, and the following two instances of that class:

class Animal

  def species
    "cat"
  end
end

maru = Animal.new
hanna = Animal.new

Given the above, what will the following return? Why?

maru == hanna

4 . Given the following class:

class Animal
  
  def species 
    my_species = "cat"
  end

  def say_species
    puts "Hi! I'm a #{my_species}"
  end
end

What will happen when we invoke the following code?

maru = Animal.new
maru.say_species

Is it broken? Why? How can you fix it?

5 . Reverse engineer this code (i.e., write the class that will make the code work as invoked below):

frederick = Animal.new("bull")
frederick.species
# => "bull"

Hint: How can you instantiate, or initialize, an instance of a class with a given value? What kind of variable would you use so that that value can be shared across instance methods within a class?

6 . Given the following code:

class Animal
  
  def initialize(species)
    @species = species
  end

end

lil_bub = Animal.new("cat")

What is the relationship between lil_bub and the Animal class?

mod-1-discussion-questions-object-orientation-in-ruby's People

Contributors

antoinfive avatar drakeltheryuujin avatar dukegreene avatar graciemcguire avatar joll59 avatar maxwellbenton avatar rajiprinze avatar realandrewcohn avatar robhitt avatar rrcobb avatar sophiedebenedetto avatar sylwiavargas avatar telegraham avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mod-1-discussion-questions-object-orientation-in-ruby's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.