Skip to content

Instantly share code, notes, and snippets.

@srinidhi-lwt
Last active June 10, 2019 19:14
Show Gist options
  • Save srinidhi-lwt/cd1f6bc32f2c2d167d78b5b08f765bc8 to your computer and use it in GitHub Desktop.
Save srinidhi-lwt/cd1f6bc32f2c2d167d78b5b08f765bc8 to your computer and use it in GitHub Desktop.
Ruby Method Hierarchy.
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