Skip to content

Commit f5b6c67

Browse files
committedNov 27, 2014
cleanup some module defn functions
1 parent 2c13270 commit f5b6c67

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed
 

‎opal/corelib/runtime.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -912,16 +912,28 @@
912912
};
913913

914914
/**
915-
Donate a newly defined method defined on a module.
915+
Define the given method on the module.
916+
917+
This also handles donating methods to all classes that include this
918+
module. Method conflicts are also handled here, where a class might already
919+
have defined a method of the same name, or another included module defined
920+
the same method.
916921
917922
@param [RubyModule] module the module method defined on
918923
@param [String] jsid javascript friendly method name (e.g. "$foo")
919924
@param [Function] body method body of actual function
920925
*/
921-
function donate_module_defn(module, jsid, body) {
922-
var included_in = module.$$dep;
926+
function define_module_method(module, jsid, body) {
927+
module.$$proto[jsid] = body;
928+
body.$$owner = module;
929+
930+
module.$$methods.push(jsid);
931+
932+
if (module.$$module_function) {
933+
module[jsid] = body;
934+
}
923935

924-
module.$$methods = module.$$methods.concat([jsid]);
936+
var included_in = module.$$dep;
925937

926938
if (included_in) {
927939
for (var i = 0, length = included_in.length; i < length; i++) {
@@ -1005,14 +1017,7 @@
10051017
*/
10061018
Opal.defn = function(obj, jsid, body) {
10071019
if (obj.$$is_mod) {
1008-
obj.$$proto[jsid] = body;
1009-
donate_module_defn(obj, jsid, body);
1010-
1011-
body.$$owner = obj;
1012-
1013-
if (obj.$$module_function) {
1014-
obj[jsid] = body;
1015-
}
1020+
define_module_method(obj, jsid, body);
10161021
}
10171022
else if (obj.$$is_class) {
10181023
obj.$$proto[jsid] = body;

0 commit comments

Comments
 (0)
Please sign in to comment.