Skip to content

Instantly share code, notes, and snippets.

@oreoshake
Last active December 13, 2015 18:28
Show Gist options
  • Save oreoshake/4955688 to your computer and use it in GitHub Desktop.
Save oreoshake/4955688 to your computer and use it in GitHub Desktop.
pull_31.rb
require 'rubygems'
require 'ruby-debug'
class A
def self.read
if @thing
@thing
elsif superclass.respond_to?(:read)
superclass.thing
else
{}
end
end
def self.set thing
@thing = thing
end
end
class B < A
def self.read
if @thing
@thing
elsif superclass.respond_to?(:read)
superclass.thing
else
{}
end
end
def self.set thing
@thing = thing
end
end
class C < A
def self.read
if @thing
@thing
elsif superclass.respond_to?(:read)
puts "If you see this without errors, we're good, right?"
superclass.read
else
{}
end
end
def self.set thing
@thing = thing
end
end
A.set 'foo'
raise "Fail" if A.read.nil? # fixed in gh-3
a = A.new
B.set 'bar'
b = B.new
raise "Fail" unless A.read == 'foo' # fixed in current pull request
raise "Fail" unless B.read == 'bar'
c = C.new
val = c.class.read
raise "Fail #{val} ?" unless val == 'foo' # fixed in gh-3, fixed in current pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment