Hi guys,
I'm trying to make a Ruby class that is very flexible as to its type and hopefully can inherit properties from a number of other classes depending on the values its initialized with:
class Test
def initialize(type,etc)
case type
when "stringio"
inherit_from_stringio_with_data(etc)
when "list"
inherit_from_enumerable_with_data(etc)
# and so on
end
end
end
Test.new("list").each do |item|
p item
end
s = Test.new("stringio")
s.seek(3)
puts s.read(2)
I know of - or rather have read of - the power of the mixin, but as far as I can tell this isn't quite laid out correctly. Does anyone have any ideas, or am I trying something that's best achieved otherways (by having, say @content
, that contains etc
as a StringIO
, Enumerable
etc).
Thanks!