Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Created December 17, 2009 08:47
Show Gist options
  • Save jmeridth/258628 to your computer and use it in GitHub Desktop.
Save jmeridth/258628 to your computer and use it in GitHub Desktop.
nested ruby object initialization in module
module MA
class B
attr_accessor :var_1, :var_2
def initialize
@var_1 = "initialized"
@var_2 = "initialized"
end
end
end
class A
def test
b = MA::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:0x26afc @var_2="initialized", @var_1="initialized">
=> B: #<MA::B:0x26afc @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