I have the following configuration:
module A module B def foo puts "foo" end end end class C include A end c = C.new c.foo NoMethodError: undefined method `foo' for #<C:0x8765284>
How to achieve the above?
Thanks.
Module B is βdefinedβ inside A, it is not βincludedβ in A. That's why you do not get access to the instance method #foo when you turn module A on C. You can do the following:
class C include A::B end C.new.foo
You can use the included callback to enable B when A enabled.
included
B
A
module A def A.included(klass) klass.include B end module B def foo puts "foo" end end end class C include A end
and the following will work
c = C.new c.foo
Source: https://habr.com/ru/post/1393278/More articles:error: "IOV_MAX is not declared (first used in this function) - c ++Common system architecture for Linux configuration tool - pythonTwitterizer TwittterTimeline NewtonSoft.JSON.JsonSerializationException problems - c #Fine Grain Lock - c ++https://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1393277/classes-to-group-some-actions-in-python&usg=ALkJrhh882xmzK3AJv2Inh4Ik76g5QetLwHow to execute code at application launch - androidSSIS Record 0x00 Hex Value to Flat File - sqlC # Script Using StreamWriter creates an extra character? - c #Context-sensitive line breaks in python - pythonReliable UDP implementation - c ++All Articles