Created
June 12, 2020 19:12
-
-
Save tejasInSiberia/71a4cf8442cab7e1b5bf1486ff4c5455 to your computer and use it in GitHub Desktop.
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
# Ruby program a private class accessed through the outer-class. | |
# public | |
class Marvel | |
# private | |
class Guardians | |
def Quill | |
puts "Legendary outlaw" | |
end | |
def Groot | |
puts "I am Groot" | |
end | |
# private_class_method :Groot | |
end | |
class Avengers | |
def Tony | |
puts "I am Iron-man" | |
end | |
end | |
# outer-class method accessing private classes | |
def fury | |
p "printed bro" | |
return Guardians.new | |
end | |
private_constant :Guardians | |
private_constant :Avengers | |
end | |
# calls fury method in Marvel call. | |
gotchaGurdian = Marvel.new.fury | |
gotchaGurdian.Groot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment