Last active
October 25, 2022 11:10
-
-
Save katakeynii/7fce4dd9ba514b961dad1efc1539786b to your computer and use it in GitHub Desktop.
Testing delegate 2
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
require "delegate" | |
class User | |
attr_accessor :firstname, :lastname, :username | |
def initialize(firstname, lastname, username) | |
@firstname = firstname | |
@lastname = lastname | |
@username = username | |
end | |
def iam | |
"Hi! I am #{firstname} #{lastname} (#{username})" | |
end | |
end | |
class PersonalProfile < DelegateClass(User) | |
attr_accessor :cover_url, :posts, :followers, :followings | |
def initialize user | |
@posts = [] | |
@followers = [] | |
@followings = [] | |
super(user) | |
end | |
end | |
class CorporateProfile < DelegateClass(User) | |
attr_accessor :cover_url, :posts, :followers, :followings, :curriculum | |
def initialize user | |
@posts = [] | |
@followers = [] | |
@followings = [] | |
super(user) | |
end | |
end | |
tonux = User.new "Tonux", "Samb", "tonux" | |
tonuxLab = PersonalProfile.new tonux | |
takkJok = PersonalProfile.new tonux | |
tonuxCorp = CorporateProfile.new tonux | |
puts tonuxLab.firstname # Tonux | |
puts takkJok.iam # Hi! I am Tonux Samb (tonux) | |
puts tonuxCorp.firstname # Tonux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment