Git Product home page Git Product logo

phase-3-ruby-oo-self-introduction's Introduction

Introduction to Self

For newly developing Rubyists, self can be a bit baffling. You've learned about the concept of the class, and that each object in Ruby has one. The keyword self is a special variable that points to the object that "owns" the currently executing code. You can think of it as a Ruby program asking, "who am I right now?". Ruby is using the concept of self to determine which execution context to use at any point in the program.

self in Ruby is used in a similar way to this in Object-Oriented JavaScript, with a few key differences that we'll cover over the course of this section.

In these few lessons, we'll demonstrate:

  • How the self keyword works
  • How to use self within an instance method to refer to the class instance on which that method is being called
  • The concept of monkey patching Ruby's built-in classes
  • How to use attr_accessor, attr_reader, and attr_writer as needed

In this section, we're going to talk about how to use self, and how to apply self in a variety of situations.

phase-3-ruby-oo-self-introduction's People

Contributors

ihollander avatar maxwellbenton avatar lizbur10 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.