Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, I'll try to help here : </p> <p>First a module is not a class, it allows you to mix behaviour in a class. second see the following example : </p> <pre><code>module A module B module Error def foobar puts "foo" end end end end class StandardError include A::B::Error end StandardError.new.kind_of?(A::B::Error) StandardError.new.kind_of?(A::B) StandardError.included_modules #=&gt; [A::B::Error,Kernel] </code></pre> <p>kind_of? tells you that yes, Error does possess All of A::B::Error behaviour (which is normal since it includes A::B::Error) however it does not include all the behaviour from A::B and therefore is not of the A::B kind. (duck typing)</p> <p>Now there is a very good chance that ruby-aws reopens one of the superclass of NameError and includes Amazon::AWS:Error in there. (monkey patching)</p> <p>You can find out programatically where the module is included in the hierarchy with the following :</p> <pre><code>class Class def has_module?(module_ref) if self.included_modules.include?(module_ref) and not self.superclass.included_modules.include?(module_ref) puts self.name+" has module "+ module_ref.name else self.superclass.nil? ? false : self.superclass.has_module?(module_ref) end end end StandardError.has_module?(A::B::Error) NameError.has_module?(A::B::Error) </code></pre> <p>Regarding your second question I can't see anything better than </p> <pre><code>begin #do AWS error prone stuff rescue Exception =&gt; e if Amazon::AWS::Error.constants.include?(e.class.name) #awsError else whatever end end </code></pre> <p>(edit -- above code doesn't work as is : name includes module prefix which is not the case of the constants arrays. You should definitely contact the lib maintainer the AWSError class looks more like a factory class to me :/ )</p> <p>I don't have ruby-aws here and the caliban site is blocked by the company's firewall so I can't test much further. </p> <p>Regarding the include : that might be the thing doing the monkey patching on the StandardError hierarchy. I am not sure anymore but most likely doing it at the root of a file outside every context is including the module on Object or on the Object metaclass. (this is what would happen in IRB, where the default context is Object, not sure about in a file)</p> <p>from the <a href="http://www.rubycentral.com/pickaxe/tut_modules.html" rel="nofollow noreferrer">pickaxe on modules</a> :</p> <p><code>A couple of points about the include statement before we go on. First, it has nothing to do with files. C programmers use a preprocessor directive called #include to insert the contents of one file into another during compilation. The Ruby include statement simply makes a reference to a named module. If that module is in a separate file, you must use require to drag that file in before using include.</code></p> <p>(edit -- I can't seem to be able to comment using this browser :/ yay for locked in platforms) </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