Skip to content

Instantly share code, notes, and snippets.

@fentontaylor
Last active June 26, 2019 17:59
Show Gist options
  • Save fentontaylor/fa5b3a75dbb428f7ed7fac0395cb1c27 to your computer and use it in GitHub Desktop.
Save fentontaylor/fa5b3a75dbb428f7ed7fac0395cb1c27 to your computer and use it in GitHub Desktop.
Fenton Taylor
What is a Class?
- A class is a blueprint for a specific type of object. Each object has attributes (instance variables) and behaviors (methods).
What is an Instance?
- An instance is a specific example of a certain class. For example, the Person class could have instances of Fenton, Alec, and Nancy. All instances of person share the same attributes, but the values of those attributes can be different for each instance.
What is an Object?
- Everything in Ruby is an object. An object is an instance of a specific class. It can be a Class, String, Integer, Float, Array, Hash, etc. and each class of objects has unique methods that it can use to manipulate or be manipulated.
What happens when we call .new on an object?
- Calling .new initializes a new object of a class. For example, Array.new initializes a new empty Array object.
What is an attribute? How can we recognize an attribute?
- An attribute is a characteristic of an object. Attributes are identified by their @ in front of the variable names.
What is a method?
- A method is a behavior. Classes have methods specific to that class that can act on the objects of that class. For example, "Hello" is a String, and .length is a method for strings. So calling "Hello".length will return 5. Methods can only work on objects of that class.
What are parameters? How do we add parameters to methods?
- Parameters are values that passed to methods. For example, the string method .include? requires a parameter to search for. Parameters are passed to methods in parentheses (though not always necessary) immediatley after the method call. EXAMPLE: "Hello".include?("e") => true, "Hello".include?("z") => false
What is a return value? How do you know what the return value of a method is? Do all methods have return values?
All methods return a value (object), even if the return value is nil. The return value of a method is whatever the last line of code is.
What is the link to your #each repl?
https://repl.it/repls/GentleEnergeticDiscussions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment