Created
August 6, 2013 14:54
-
-
Save rentalcustard/6165204 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
#if I have... | |
A.new(B.new(C.new(D.new))) | |
#is there some way (some inject sorcery?) to construct this from a list of the classes? | |
list = [A, B, C, D] |
class X
def initialize(other)
@other = other
end
end
class A < X; end
class B < X; end
class C < X; end
class D < X; end
[ A, B, C, D ].reverse.inject { |acc, klass| klass.new(acc) }
I finally settled on
[A, B, C].reverse.inject(D.new) {|acc, klass| klass.new(acc) }
Which is obviously cheating, but whatever.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe something like this?