Skip to content

Instantly share code, notes, and snippets.

@idlehands
Created November 4, 2012 20:09
Show Gist options
  • Save idlehands/4013455 to your computer and use it in GitHub Desktop.
Save idlehands/4013455 to your computer and use it in GitHub Desktop.
Passing 'self' as a parameter when creating an instance of another class.
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