Last active
June 10, 2019 20:51
-
-
Save srinidhi-lwt/90a1cdfb4771dff4e2f4939a7a2e1f4f 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 Developer | |
def name | |
puts "Hi. This is Employee" | |
end | |
end | |
e = Employee.new | |
def e.name | |
puts 'Hi. This is e object' | |
end | |
e.extend(Analyst) | |
e.name | |
=> 'Hi. This is e object' | |
e.class.ancestors | |
=> [Employee, Developer, Object, Kernel, BasicObject] | |
######################################### | |
module Developer | |
def name | |
puts "Hi. This is Developer" | |
end | |
end | |
module Analyst | |
def name | |
puts "Hi. This is Analyst" | |
super | |
end | |
end | |
class Employee | |
include Developer | |
def name | |
puts "Hi. This is Employee" | |
super | |
end | |
end | |
e = Employee.new | |
def e.name | |
puts 'Hi. This is e object' | |
super | |
end | |
e.extend(Analyst) | |
e.name | |
=> 'Hi. This is e object' | |
'Hi. This is Analyst' | |
'Hi. This is Employee' | |
'Hi. This is Developer' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment