Sha256: 1a36efef484ae53c38537f3a0fd31cf62ed071cef59aacfe47a032d259e08ec8
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
opal-0.3.1 | gems/core/lib/core/module.rb |
opal-0.3.0 | gems/core/lib/core/module.rb |