Created
October 21, 2012 20:26
-
-
Save mbj/3928397 to your computer and use it in GitHub Desktop.
Ruby imperfectness?
This file contains 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
module ModuleWithMethod | |
def the_method | |
end | |
end | |
class ModuleWithContext < ::Module | |
def initialize(context) | |
@context = context | |
end | |
def the_method_with_context | |
@context | |
end | |
end | |
class Foo | |
extend ModuleWithMethod | |
extend ModuleWithContext.new(:the_context) | |
p method(:the_method) | |
p method(:the_method_with_context) | |
end | |
# A: Somewhere deep into ruby is a def extend(mod); return unless mod.class == ::Module; make_methods_available_from(mod); end | |
# B: I understood something fundamental in the wrong way. | |
This file contains 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
#<Method: Class(ModuleWithMethod)#the_method> | |
NameError: undefined method `the_method_with_context' for class `#<Class:0x2dc0435>' | |
method at org/jruby/RubyKernel.java:2054 | |
Foo at extend_module_with_context.rb:21 | |
(root) at extend_module_with_context.rb:16 |
This file contains 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
#<Method: Class#the_method (defined in ModuleWithMethod at /home/mbj/devel/3928397/extend_module_with_context.rb:2)> | |
An exception occurred running extend_module_with_context.rb | |
undefined method `the_method_with_context' for Foo (NameError) | |
Backtrace: | |
[0;31m Kernel(Class)#method at kernel/common/kernel18.rb:163[0m | |
Foo.__class_init__ (Foo) at extend_module_with_context.rb:21[0m | |
Object#__script__ at extend_module_with_context.rb:16[0m | |
[0;34m Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:68[0m | |
[0;34m Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:110[0m | |
[0;34m Rubinius::Loader#script at kernel/loader.rb:614[0m | |
[0;34m Rubinius::Loader#main at kernel/loader.rb:815[0m |
This file contains 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
#<Method: Class(ModuleWithMethod)#the_method> | |
extend_module_with_context.rb:21:in `method': undefined method `the_method_with_context' for class `Class' (NameError) | |
from extend_module_with_context.rb:21 |
This file contains 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
#<Method: Class(ModuleWithMethod)#the_method> | |
extend_module_with_context.rb:21:in `method': undefined method `the_method_with_context' for class `Class' (NameError) | |
from extend_module_with_context.rb:21:in `<class:Foo>' | |
from extend_module_with_context.rb:16:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment