Skip to content

Commit

Permalink
Make sure alias_method donates new methods to module includees
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 8, 2013
1 parent a336419 commit 442b7f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion corelib/module.rb
Expand Up @@ -39,7 +39,13 @@ def ===(object)
end

def alias_method(newname, oldname)
`#{self}._proto['$' + newname] = #{self}._proto['$' + oldname]`
%x{
#{self}._proto['$' + newname] = #{self}._proto['$' + oldname];
if (self._methods) {
$opal.donate(self, ['$' + newname ])
}
}
self
end

Expand Down
20 changes: 19 additions & 1 deletion spec/opal/module/alias_method_spec.rb
@@ -1,4 +1,14 @@
class AliasMethodSpec
module M
def something
3.142
end

alias_method :something_else, :something
end

include M

def foo; 'foo'; end
alias_method :bar, :foo
end
Expand All @@ -7,4 +17,12 @@ def foo; 'foo'; end
it "makes a copy of the method" do
AliasMethodSpec.new.bar.should == 'foo'
end
end

describe "inside a module" do
it "defined methods that get donated to a class when included" do
obj = AliasMethodSpec.new
obj.something.should == 3.142
obj.something_else.should == 3.142
end
end
end

0 comments on commit 442b7f5

Please sign in to comment.