-
-
Save baroquebobcat/4022150 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
| module A | |
| refine(A) {} | |
| using A | |
| end | |
| #a.rb:3: stack level too deep (SystemStackError) |
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
| def require x | |
| if x.include? 'core_ext' and !x.include? 'psych' | |
| puts "wtf #{x}", caller.first | |
| else | |
| super | |
| end | |
| end | |
| module ActiveSupportCoreRefinements | |
| active_support_no_deps, active_support_deps = Dir[Gem.find_files('active_support/core_ext').first.sub('.rb','') + "/**/*.rb"].partition do |core_ext| | |
| file_contents = open(core_ext).read | |
| !file_contents.match /require.*core_ext.*/ | |
| end | |
| def self.refineify file_contents, file | |
| file_contents.gsub!(/^\s*require\s*.*core_ext.*\s*$/, '') | |
| if file_contents.gsub!(/^\s*(class|module) (\S*)\s*$/i, "refine \\2 do") | |
| eval file_contents rescue puts "#{file} failed to eval" | |
| puts 1.day, file rescue print '.' | |
| end | |
| end | |
| ActiveSupportCoreRefinementsBase = Module.new do | |
| active_support_no_deps.each do |core_ext| | |
| file_contents = open(core_ext).read | |
| ActiveSupportCoreRefinements.refineify file_contents, core_ext | |
| end | |
| end | |
| using ActiveSupportCoreRefinementsBase | |
| puts nil, "dependent" | |
| active_support_deps.each do |core_ext| | |
| file_contents = open(core_ext).read | |
| refineify file_contents, core_ext | |
| end | |
| end |
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
| module A | |
| refine String do | |
| def a | |
| puts "a" | |
| end | |
| def b | |
| a | |
| end | |
| end | |
| end | |
| using A | |
| "b".b | |
| # a |
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
| module A | |
| refine String do | |
| def a | |
| puts "a" | |
| end | |
| end | |
| end | |
| module B | |
| refine String do | |
| using A | |
| def b | |
| a | |
| end | |
| end | |
| end | |
| using A | |
| using B | |
| "b".b | |
| #a |
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
| module A | |
| refine String do | |
| def a | |
| puts "a" | |
| end | |
| end | |
| end | |
| module B | |
| refine String do | |
| def b | |
| a | |
| end | |
| end | |
| end | |
| using A | |
| using B | |
| "b".b | |
| #a.rb:13:in `b': undefined local variable or method `a' for "b":String (NameError) | |
| # from a.rb:20:in `<main>' |
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
| module A | |
| refine String do | |
| def a | |
| puts "a" | |
| end | |
| end | |
| end | |
| module B | |
| using A | |
| refine String do | |
| def b | |
| a | |
| end | |
| end | |
| end | |
| using A | |
| using B | |
| "b".b | |
| # a |
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
| module A | |
| refine Array do | |
| def b_me | |
| puts "b" | |
| end | |
| end | |
| refine String do | |
| using A | |
| def b | |
| [].b_me | |
| end | |
| end | |
| end | |
| using A | |
| "b".b | |
| # b |
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
| module A | |
| refine String do | |
| using A | |
| def b | |
| [].b_me | |
| end | |
| end | |
| refine Array do | |
| def b_me | |
| puts "b" | |
| end | |
| end | |
| end | |
| using A | |
| "b".b | |
| #a.rb:5:in `b': undefined method `b_me' for []:Array (NoMethodError) | |
| # from a.rb:17:in `<main>' |
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
| module A | |
| refine String do | |
| def a | |
| puts "a" | |
| end | |
| end | |
| refine String do | |
| def b | |
| a | |
| end | |
| end | |
| end | |
| using A | |
| "b".b | |
| # a |
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
| module A | |
| refine String do | |
| def b | |
| a | |
| end | |
| end | |
| refine String do | |
| def a | |
| puts "a" | |
| end | |
| end | |
| end | |
| using A | |
| "b".b | |
| # a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment