Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created February 12, 2012 20:16
Show Gist options
  • Save cadwallion/1810692 to your computer and use it in GitHub Desktop.
Save cadwallion/1810692 to your computer and use it in GitHub Desktop.
Namespace derivation problem
# EXPECTED OUTPUT
a = Foo::Bar.new
b = AnotherFoo::AnotherBar.new
a.thing # => [1,2,3,4]
b.thing # => [5,6,7,8]
class Foo
def self.thing
[1,2]
end
class Bar < ::Baz
def initialize
@data = [3,4]
end
end
end
class AnotherFoo
def self.thing
[5,6]
end
class AnotherBar < ::Baz
def initialize
@data = [7,8]
end
end
end
class Baz
def thing
more_data = @data
# THIS NEEDS TO COMBINE more_data with its corresponding Foo#thing or AnotherFoo#thing depending upon the immediate namespace of the class
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment