Last active
June 10, 2019 19:14
-
-
Save srinidhi-lwt/cd1f6bc32f2c2d167d78b5b08f765bc8 to your computer and use it in GitHub Desktop.
Ruby Method Hierarchy.
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
module Developer | |
def name | |
puts "Hi. This is Developer" | |
end | |
end | |
class Employee | |
def name | |
puts "Hi. This is Employee" | |
end | |
end | |
class Analyst < Employee | |
include Developer | |
def name | |
puts "Hi. This is Analyst" | |
end | |
end | |
analyst = Analyst.new | |
analyst.name | |
=> 'Hi. This is Analyst' | |
analyst.class.ancestors | |
=> [Analyst, Developer, Employee, Object, Kernel, BasicObject] | |
################################################# | |
module Developer | |
def name | |
puts "Hi. This is Developer" | |
super | |
end | |
end | |
class Employee | |
def name | |
puts "Hi. This is Employee" | |
end | |
end | |
class Analyst < Employee | |
include Developer | |
def name | |
puts "Hi. This is Analyst" | |
super | |
end | |
end | |
analyst = Analyst.new | |
analyst.name | |
=> 'Hi. This is Analyst' | |
=> 'Hi. This is Developer' | |
=> 'Hi. This is Employee' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment