I have the following class:
class Alphabet
attr_reader :letter_freqs, :statistic_letter
def initialize(lang)
@lang = lang
case lang
when :en
@alphabet = ('A'..'Z').to_a
@letter_freqs = { ... }
when :ru
@alphabet = ('А'..'Я').to_a.insert(6, 'Ё')
@letter_freqs = { ... }
...
end
@statistic_letter = @letter_freqs.max_by { |k, v| v }[0]
end
end
foo = Alphabet.new(:en)
The central member here is @alphabet
.
I'd like to make it some sort of a container class to invoke Array methods directly like
foo[i]
foo.include?
instead of explicitly accessing @alphabet
:
foo.alphabet[i]
foo.alphabet.include?
I know I could define a lot of methods like
def [](i)
@alphabet[i]
end
but I'm looking for a proper way of "inheriting" them.