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