Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Created November 6, 2012 02:22
Show Gist options
  • Select an option

  • Save baroquebobcat/4022150 to your computer and use it in GitHub Desktop.

Select an option

Save baroquebobcat/4022150 to your computer and use it in GitHub Desktop.
module A
refine(A) {}
using A
end
#a.rb:3: stack level too deep (SystemStackError)
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
module A
refine String do
def a
puts "a"
end
def b
a
end
end
end
using A
"b".b
# a
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
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>'
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
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
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>'
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
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