inheritance - Module methods in Ruby -


here code:

module star   def star.line     puts '*' * 20   end end  module dollar   def star.line     puts '$' * 20   end end  module @   def line     puts '@' * 20   end end  include @ dollar::line # => "@@@@@@@@@@@@@@@@@@@@" star::line   # => "$$$$$$$$$$$$$$$$$$$$" dollar::line # => "@@@@@@@@@@@@@@@@@@@@" line         # => "@@@@@@@@@@@@@@@@@@@@" 

can explain how result? not understand method lookup flow here.

this how see it:

dollar::line

there no such method defined in module it's calling at::line because included module.

star::line

it uses last defining dollar module(it goes after original star definition it's overridden).

dollar::line

third call same first one.

line

and last 1 at::line because made include.


Comments