Created
December 17, 2009 09:19
-
-
Save jmeridth/258642 to your computer and use it in GitHub Desktop.
access ruby object from module via include
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
module MA | |
class B | |
attr_accessor :var_1, :var_2 | |
def initialize | |
@var_1 = "initialized" | |
@var_2 = "initialized" | |
end | |
end | |
end | |
class A | |
include MA | |
def test | |
b = B.new | |
puts "B's instance variables: #{b.instance_variables}" | |
puts "B: #{b.inspect}" | |
b.var_1 = "re_initialized" | |
b.var_2 = "re_initialized" | |
puts "B: #{b.inspect}" | |
end | |
end | |
a = A.new | |
a.test | |
=> B's instance variables: @var_2@var_1 | |
=> B: #<MA::B:0x26a70 @var_2="initialized", @var_1="initialized"> | |
=> B: #<MA::B:0x26a70 @var_2="re_initialized", @var_1="re_initialized"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment