Giter Club home page Giter Club logo

mod-1-discussion-questions-using-self-in-ruby's Introduction

self 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.

funny robots

1 .

  class FunnyBots  

    attr_accessor :name, :quotes  

    @@bots = []

    def initialize(name, quotes)
      @name = name
      @quotes = quotes
      @@bots << self
    end

   def random_quote
      self.quotes.sample
    end

    def self.bots
      @@bots
    end

end

  archer = FunnyBots.new("Archer", ["Q: How did the programmer die in the shower? A:He read the shampoo bottle instructions: Lather. Rinse. Repeat. ", "A UI is like a joke. If you have to explain it, it's not good.", "Q: How many programmers does it take to change a light bulb? A: None – It’s a hardware problem"] )

A. What is self in this line @@bots << self ?
B. What is self in this line self.quotes.sample?
C. What kind of method is self.bots & what is self? D. Will this work archer.bots? Why / why not?

2 .

Photo by C Drying on Unsplash.

class Bicycle

  attr_reader :tire

    def initialize(tire, gears, style)
      @tire = tire
      @gears = gears
      @style = style
    end

    def tire_size
      self.tire
    end

    def self.gears
      @gears
    end

end

mongoose = Bicycle.new(4, 10, "BMX")

For what reasons will the following method calls fail :mongoose.tire_size = 5, mongoose.gears, Bicycle.bikes, Bicycle.styles? Restructure the class to fix the issues.

View Week 1 Day 5 Discussion on Learn.co and start learning to code for free.

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.