Skip to content

Commit

Permalink
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion corelib/module.rb
Original file line number Diff line number Diff line change
@@ -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

20 changes: 19 additions & 1 deletion spec/opal/module/alias_method_spec.rb
Original file line number Diff line number Diff line change
@@ -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
@@ -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.