Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Created December 17, 2009 09:19
Show Gist options
  • Save jmeridth/258642 to your computer and use it in GitHub Desktop.
Save jmeridth/258642 to your computer and use it in GitHub Desktop.
access ruby object from module via include
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