Created
October 18, 2013 05:59
-
-
Save dirk/7037103 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module { | |
forwards_unary_ruby_methods | |
def [constant_name] { | |
""" | |
@constant_name Name (@String@) of constant's name. | |
@return @constant_name's value. | |
Returns the value of the constant with the given name in @self. | |
""" | |
const_get(constant_name) | |
} | |
def [constant_name]: value { | |
""" | |
@constant_name Name (@String@) of constant's name. | |
@value New value of constant to be used. | |
Sets the value of a constant with the given name in @self. | |
""" | |
const_set(constant_name, value) | |
} | |
def included: module { | |
""" | |
@module @Module@ or @Class@ that has been included into @self. | |
Gets called when a @Class@ or @Module@ is included into another @Class@. | |
""" | |
# do nothing by default | |
nil | |
} | |
def overwrite_method: name with_dynamic: block { | |
# rubinius/kernely/common/module.rb line 843 | |
# def dynamic_method(name, file="(dynamic)", line=1) | |
g = Rubinius ToolSet Runtime Generator new() | |
g name=(name to_sym) | |
g file=("(dynamic)" to_sym) | |
g set_line(1) | |
block call: g | |
g close() | |
g use_detected() | |
g encode() | |
code = g.package(Rubinius CompiledCode) | |
code scope=(Rubinius ConstantScope new(self, Rubinius ConstantScope new(Object))) | |
# rubinius/kernel/delta/rubinius.rb line 119 | |
# Rubinius.add_method(name, code, self, :public) | |
visibility = 'public | |
old_doc = self method_table lookup(name) method() documentation | |
self method_table store(name, code, visibility) | |
Rubinius VM reset_method_cache(self, name) | |
self method_table lookup(name) method() documentation: (old_doc instance_variable_get('@docs)) | |
return code | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment