Created
November 4, 2012 20:09
-
-
Save idlehands/4013455 to your computer and use it in GitHub Desktop.
Passing 'self' as a parameter when creating an instance of another class.
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
class Uber_class | |
attr_accessor :color | |
def initialize(color) | |
@color = color | |
@bob = Underling.new(self) | |
end | |
def run | |
@bob.test | |
end | |
def put_test | |
puts @color | |
end | |
end | |
class Underling | |
attr_accessor :master_instance | |
def initialize(instance) | |
@master_instance = instance | |
end | |
def test | |
@master_instance.put_test | |
end | |
end | |
uber = Uber_class.new("hot pink") | |
uber.run | |
uber2 = Uber_class.new("blue") | |
uber2.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment