Skip to content

Instantly share code, notes, and snippets.

@adriculous
Created July 28, 2016 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adriculous/55773fb9a34210ff6a463ca04903ec2d to your computer and use it in GitHub Desktop.
Save adriculous/55773fb9a34210ff6a463ca04903ec2d to your computer and use it in GitHub Desktop.
Ver. 1 of the object oriented sample code
# 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