Created
July 28, 2016 08:00
-
-
Save adriculous/55773fb9a34210ff6a463ca04903ec2d to your computer and use it in GitHub Desktop.
Ver. 1 of the object oriented sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Doing some OOP (object oriented programming) where we can create our own objects and define them. I'll be using manga information as my example. | |
class Manga | |
def set_title=(title) | |
@title = title | |
end | |
def get_title | |
return @title | |
end | |
def set_mangaka=(mangaka) | |
@mangaka = mangaka | |
end | |
def get_mangaka | |
return @mangaka | |
end | |
def set_genre=(genre) | |
@genre = genre | |
end | |
def get_genre | |
return @genre | |
end | |
def about_manga | |
return "A good #{@genre} manga that I recommend for everyone to read is #{@mangaka}'s #{@title}." | |
end | |
end | |
my_manga = Manga.new | |
my_manga.set_title = 'Cardcaptor Sakura' | |
my_manga.set_mangaka = 'CLAMP' | |
my_manga.set_genre = 'adventure' | |
puts my_manga.about_manga |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment