Skip to content

Commit

Permalink
Fix bug with accessors defined in modules (fixes #388)
Browse files Browse the repository at this point in the history
Accessors defined in modules were not being inherited by classes that
included the module. This commit fixes that bug by adding accessors to
the donate list which a module keeps track of.
  • Loading branch information
adambeynon committed Oct 6, 2013
1 parent 4639b80 commit 36b4f94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions corelib/module.rb
Expand Up @@ -123,6 +123,7 @@ def attr_reader(*names)
}
else {
proto['$' + name] = func;
$opal.donate(self, ['$' + name ]);
}
})(names[i]);
}
Expand All @@ -144,6 +145,7 @@ def attr_writer(*names)
}
else {
proto['$' + name + '='] = func;
$opal.donate(self, ['$' + name + '=']);
}
})(names[i]);
}
Expand Down
18 changes: 18 additions & 0 deletions spec/opal/module/attr_accessor_spec.rb
@@ -1,8 +1,26 @@
require 'spec_helper'

module AttrAccessorSpec
module M
attr_accessor :foo
end

class C
include M
end
end

describe "Module#attr_accessor" do
it "can be passed a splat of arguments" do
eval "class OpalAttrAccessorSpec; attr_accessor *%w{foo bar baz}; end"
OpalAttrAccessorSpec.new.foo.should be_nil
end

describe "inside a module" do
it "defines methods that get donated to a class when included" do
obj = AttrAccessorSpec::C.new
obj.foo = 100
obj.foo.should == 100
end
end
end

0 comments on commit 36b4f94

Please sign in to comment.