|
912 | 912 | };
|
913 | 913 |
|
914 | 914 | /**
|
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. |
916 | 921 |
|
917 | 922 | @param [RubyModule] module the module method defined on
|
918 | 923 | @param [String] jsid javascript friendly method name (e.g. "$foo")
|
919 | 924 | @param [Function] body method body of actual function
|
920 | 925 | */
|
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 | + } |
923 | 935 |
|
924 |
| - module.$$methods = module.$$methods.concat([jsid]); |
| 936 | + var included_in = module.$$dep; |
925 | 937 |
|
926 | 938 | if (included_in) {
|
927 | 939 | for (var i = 0, length = included_in.length; i < length; i++) {
|
|
1005 | 1017 | */
|
1006 | 1018 | Opal.defn = function(obj, jsid, body) {
|
1007 | 1019 | 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); |
1016 | 1021 | }
|
1017 | 1022 | else if (obj.$$is_class) {
|
1018 | 1023 | obj.$$proto[jsid] = body;
|
|
0 commit comments