Nice to meet you. I'm Mackey, a college engineer. This time, I tried to summarize the object-oriented programming that I didn't understand so far in my own way. In addition, the language used this time is Ruby. It's the first Qiita article, so I think there are some strange things, but I don't know.
・ In ruby, all values are objects -Objects can be created from classes -The object belongs to some class ・ Understand the concept of variables
・ Kinocode / Programming learning video YouTuber's [Ruby Super Introductory Course] 13. Class | A class is a collection of "data" and "processing"![Introduction course for programming beginners] https://www.youtube.com/watch?v=E5IX_WLuvcs&list=PLavQwENTsEBUAgSok7Ww4-Q-ZHissbMOv&index=14
This person's explanation is very easy to understand, so please subscribe to the channel.
I think that one of the barriers that beginners of programming encounter when programming is objects, classes, instances, methods, and so on. So I would like to explain each word to beginners without technical terms.
A class is an image of a blueprint or a skeleton.
Instance is a term used when you want to emphasize an object created from a class.
Class.rb
//Student class generation
class Student
//The initialize method is a method that is automatically executed when an object is created.
def initialize(student_name)
@name = student_name
end
//A method to display the average score of math and English
def average(math,english)
result = (math + english) / 2
p @name,result
end
end
//Create object
a = Student.new("tanaka")
//Execute average method on instance a of student class
a.average(50,30)
Recommended Posts