From: Chirag Mistry [mailto:chirag80bece / gmail.com] 
# Pea, Botp wrote:
# > From: Robert Dober [mailto:robert.dober / gmail.com]
# > # p C2.ancestors - (Class.new.ancestors + [C2])
# E.g.
# ----
# module IN
# end
# 
# module M1
#   include IN
# end
# 
# module M2
#   include IN
# end
# 
# class C
#   include M1
#   include M2
#   ...
# end
# ----
#      If we try above solution then I will get M1, M2, IN and 
# Kernel. But 
# I want list which contains M1 and M2 only because these both are 
# included directly in class C.

again, you can do fred's technique or 

you can do plain subtraction. get the included modules of each and subtract it from the main...

something like,

irb(main):059:0* M1.included_modules
=> [IN]
irb(main):060:0> M2.included_modules
=> [IN]
irb(main):061:0> IN.included_modules
=> []

....
irb(main):055:0> mymodules = C.included_modules - [Kernel]
=> [M2, M1, IN]
irb(main):056:0> mymodules.each {|m| mymodules -= m.included_modules}
=> [M2, M1, IN]
irb(main):057:0> mymodules
=> [M2, M1]


kind regards -botp