-
Notifications
You must be signed in to change notification settings - Fork 0
/
wk6_review_reflect.txt
21 lines (18 loc) · 2.72 KB
/
wk6_review_reflect.txt
1
1. What are classes? Be sure to define the following terms in your explanation and describe the relationships between them:• class• state• behavior• instance variable• instance methodClasses in ruby are like a cookie-cutter. They are molding by which you can pass through data, and it will process that data in a certain way. It can be used again and again with similar types of data, each processed in the same way. Classes comprise of state, or “instance variables” and behavior, or “methods.” The state is private to the class object, unless it is made public via publicly accessible methods. Instance variables, or “state” is a variable which is initialized, which gives it the ability to be accessible inside any method inside the class. We could think of them as global variables within the scope of the class. They always begin with the @ sign. From what I can gather, ruby classes primarily have two types of methods (might be more, but I’ll address the ones I’m aware of), which are class methods and instance methods. Class methods are related to the parent class and will have the word “self” attached or next to them (def self.process or Game << self). Instance methods are more similar to the types of methods we are all familiar with, where it is defined in the more common way which would also be used outside of a class, like def process. Instance methods only work with the instance, so you need to create a new one for each instance. Class methods can only be called on classes and instance methods can only be called on instances.2. What are attributes?Attributes are specific properties of an object and can only be accessible inside the class unless you provide attr_reader/writer/accessor or getter/setter methods.3. Give an example of a real world object, and describe how you might assign its attributes if you were to design a class to represent that object.A real world example of an object is a recipe or a how to instructional. For example, the class would be grow a tomato plant. def plant seeds(20), def water(3 cups), sunshine(8 hours), time(3 months), while tomato is green continue. If tomato is red, pluck, wash, and eat. 4. What is the purpose of the initialize method? When does it run?The purpose of the initialize method is to create instance variables, which start with the @ sign and are globally accessible inside the scope of the class.5. What are modules?Modules are similar to classes, but they are specifically geared towards functions or methods whereas classes are primarily focused on objects. There can be mixins where they interact with each other.6. What are the different ways you can use a module?You could use a module by itself, or as a mixin incorporating classes.