Giter VIP home page Giter VIP logo

ruby-oo-class-variables-quiz's Introduction

Quiz: Class Variables and Methods

???

Class Variables and Methods

?: Classes are objects.

(X) True ( ) False

?: What type of scope does a class variable have?

( ) Local ( ) Global ( ) Instance (X) Class

?: What is the syntax for a class variable?

( )@variable_name (X)@@variable_name ( )$variable_name ( ) VARIABLE_NAME

?:

def self.class_method_name
  # some code
end

In this code sample, what does the keyword self refer to?

(X) The entire class itself ( ) An instance of the class ( ) Local scope ( ) Instance scope

?: Private methods can only be called within the context of the defining class. The receiver of a private method is always self.

(X) True ( ) False

?: Private methods, including initialize, are usually written with the word "private" above them.

( ) True (X) False

?:

class Book

  attr_accessor :name

  def initialize(name)
    @name = name
  end
end

What syntax should be used to to create a class variables that stores new instances of Book as soon as they're created?

( )

class Book

  @@all = []

  attr_accessor :name

  def initialize(name)
    @name = name
  end
end

( )

class Book
  attr_accessor :name

  def initialize(name)
    @name = name
    @@all << self
  end
end

(X)

class Book

  @@all = []

  attr_accessor :name

  def initialize(name)
    @name = name
    @@all << self
  end
end

( ) None of the Above

?: What type of constant is defined within a class that are available to all instances of a particular class?

( ) Instance ( ) Local ( ) Global (X) Class

?: To create a class constant, what syntax should be used?

( )@variable_name ( )@@variable_name ( )$variable_name (X) VARIABLE_NAME

?:

class Book
  attr_accessor :author, :page_count, :genre
  attr_reader :title

  GENRES = []

  def initialize(title)
    @title = title
  end

  def turn_page
    puts "Flipping the page...wow, you read fast!"
  end

end

If we wanted to modify the above code so that the genre of every Book instance is stored in the GENRES class constant, what needs to change in the above code?

( ) Create the writer for genre and add the logic for the class constant ( ) Add an attr_reader for genre ( ) Remove the attr_accessor for genre (X) All of the Above

???

ruby-oo-class-variables-quiz's People

Contributors

drakeltheryuujin avatar maxwellbenton 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  avatar  avatar

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.