include - Ruby module with a static method call from includer class -


I need to define stability in the module using the method from the class included in this module:

  Module B DRF self.included (base) class & lt; & Lt; The base CONST = self.find end-end end class AF self.find "AAA" is finally included in a B: CONST  

but the compiler returns an error on the 4th row.

Is there any other way of defining stability?

The more idiomatic ways to get it in Ruby:

  module B DRF self.included (Class) Clays. Class_val & lt; & Lt; -ruby_eval CONST = rabbi_evail # Note that the block form of class_ option will not work # Because you can not assign a constant end-end class ARF self.find "AAA" in the end B. Finally A :: CONST  

What were you doing (class and lieutenant; & lt; basis) actually puts you in the context of A's MetaCLASS , not find yourself a The method itself is on its own, it does not have metacalls. Land that classes themselves are objects, and they have their Metaclas.

To try to make it clear:

  class human def parent # this method is available on human class and is available for all examples of # Lt; & Lt; Self-def build # This method is available on human metaclaces, and # is available for example, if the human beings themselves end # # "self" here is a human's metaclass, build # can not be called end DEF self.build # In the same way as the above end # build "Self" itself is human, so it can be called #and end and call  

Not sure if it helps, but If you do not understand it, then you still use the above class_eval idiom Can be


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -