# Implements the core functionality of modules. This is inherited from # by instances of {Class}, so these methods are also available to # classes. class Module def name `return self.__classid__;` end def ===(obj) obj.kind_of? self end def define_method(method_id, &block) raise LocalJumpError, "no block given" unless block_given? `VM.define_method(self, #{method_id.to_s}, block)` nil end def attr_accessor(*attrs) attr_reader *attrs attr_writer *attrs end def attr_reader(*attrs) `for (var i = 0; i < attrs.length; i++) { var attr = attrs[i]; var method_id = #{`attr`.to_s}; VM.define_method(self, method_id, new Function('self', 'var iv = self["@' + method_id + '"]; return iv === undefined ? nil : iv;')); } return nil;` end def attr_writer(*attrs) `for (var i = 0; i < attrs.length; i++) { var attr = attrs[i]; var method_id = #{`attr`.to_s}; VM.define_method(self, method_id + '=', new Function('self', 'val', 'return self["@' + method_id + '"] = val;')); } return nil;` end def alias_method(new_name, old_name) new_name = new_name.to_s old_name = old_name.to_s `VM.define_method(self, new_name, self.$m_prototype_tbl[old_name])` self end def to_s `return self.__classid__;` end def const_set(id, value) `return rb_vm_cs(self, #{id.to_s}, value);` end def class_eval(str, &block) if block_given? `block(self)` else raise "need to compile str" end end def module_eval(str, &block) class_eval str, &block end def private self end def public self end def protected self end def include(mod) `VM.include_module(self, mod)` nil end def extend(mod) `VM.extend_module(self, mod)` nil end end