Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see, what's wrong, but are you sure there was no type and you requested the file you expected?</p> <p>I would modify the code a bit:</p> <pre><code>class Hola::Translator def initialize(language, exceptions = false) @language = language @exceptions = exceptions end def hi case @language when :spanish "hola mundo" when :english "hello world" else raise ArgumentError, "Unsupported language #{@language.inspect}" if @exceptions "hello world" end end end </code></pre> <p>You support two languages: Spanish and English. Other languages are detected and you can select, if you get an error or an alternative (english) text.</p> <p>You can start it with:</p> <pre><code> class Hola def self.hi(language = :english) translator = Translator.new(language, true) ## &lt;-- Modified translator.hi end end require 'hola/translator' </code></pre> <p>One advantage of the expection: You can see, which file really calls the exception.</p> <p>Some other remarks:</p> <ul> <li>I would recommend to define <code>Hola</code> as a module, not a class.</li> <li>Instead the <code>raise</code> you could define a logger and report an error.</li> </ul> <p>Example:</p> <pre><code>require 'log4r' module Hola LOG = Log4r::Logger.new('Hola') class Translator def initialize(language) @language = language end def hi case @language when :spanish "hola mundo" when :english "hello world" else LOG.error("Unsupported language #{@language.inspect}") "hello world" end end end def self.hi(language = :english) translator = Translator.new(language) translator.hi end end #module Hola p Hola.hi p Hola.hi(:english) p Hola.hi(:spanish) p Hola.hi(:german) puts "Activate Hola-warnings" Hola::LOG.outputters &lt;&lt; Log4r::StdoutOutputter.new('stdout') p Hola.hi p Hola.hi(:english) p Hola.hi(:spanish) p Hola.hi(:german) </code></pre> <p>After activating the logger, you are informed, if you have a type in <code>:spanish</code> (that's the error I would expect).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload