Class: MorseCode::Encoders::Base
- Inherits:
-
Object
- Object
- MorseCode::Encoders::Base
- Defined in:
- lib/morse_code/encoders/base.rb
Instance Attribute Summary collapse
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(word = '') ⇒ Base
constructor
A new instance of Base.
- #supported? ⇒ Boolean
- #supported_class ⇒ Object
Constructor Details
#initialize(word = '') ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/morse_code/encoders/base.rb', line 14 def initialize(word = '') @word = word end |
Instance Attribute Details
#word ⇒ Object (readonly)
Returns the value of attribute word.
12 13 14 |
# File 'lib/morse_code/encoders/base.rb', line 12 def word @word end |
Class Method Details
.inherited(subclass) ⇒ Object
7 8 9 10 |
# File 'lib/morse_code/encoders/base.rb', line 7 def self.inherited(subclass) @@subclasses ||= [] @@subclasses << subclass end |
Instance Method Details
#supported? ⇒ Boolean
18 19 20 |
# File 'lib/morse_code/encoders/base.rb', line 18 def supported? raise NotImplementedError, 'Subclass must override supported? method' end |
#supported_class ⇒ Object
22 23 24 25 26 |
# File 'lib/morse_code/encoders/base.rb', line 22 def supported_class supported_class = Array(@@subclasses).detect { |subclass| subclass.new(word).supported? } puts "[WARING] Not Classs can encode #{word}!" unless supported_class supported_class end |