ruby, why using a module inside a module? -


trying perform remoteauthetication devise, ran example (almost official one, since devise wiki limited refer this document).

all classes implement authentication algorithm "double" enclosed either devise, models or devise, strategies.
here devise, models example:

module devise   module models     module remoteauthenticatable        extend activesupport::concern        def remote_authentication(authentication_hash)         # logic authenticate external webservice       end      end   end end 

first question: how can explain ruby newbie (as am), maybe coming language, such java, rationale of sort of namespace?
while namespaces in different flavours common among programming languages, particular way of using them new me.
in other languages 1 wouldn't use same namespace of thirdy party library (such devise in case) even when implementing interfaces or extending classes provided it.

but here see devise itself, in bits, defines

module devise   module models      module authenticatable      extend activesupport::concern      ...   end end 

second question: here module authenticatable seems extend module. found lots of docs classes including or extending other modules, not modules extending other modules. purpose of this?

if @ object model, ruby modules appended ancestors chain in classes. so:

module b; end class   include b end a.ancestors # => a, b, etc. 

now when b extends module:

module c   def a_module_method; end end module b; extend c; end 

then ruby adds a_module_method class methods in ancestors chain. can do:

a.a_module_method 

so different way give access module methods. rationale isolate instance methods class methods.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -