🖥

#Ruby nested class and module pattern : child class or module not ove

2019/12/09に公開
```rb
# A is class

class A
end

A.class
# => Class



# A is class and B is class

class A::B
end

A.class
# => Class

A::B.class
# => Class


# A is class but C is module

module A::C
end

A.class
# => Class

A::B.class
# => Class

A::C.class
# => Module

A::C.ancestors
# => [A::C]


# Unable to replace class to module or module to class


module A
end
# TypeError: A is not a module

module A::B
end
# TypeError: B is not a module

class A::C
end
# TypeError: C is not a class



# when Module is parent pattern

module D
end

module D::E
end

class D::F
end

D.class
# => Module

D::E.class
# => Module

D::F.class
# => Class


# Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/2827








<!-- Update From Qiita API -->

# チャットメンバー募集


何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ





# Twitter


https://twitter.com/YumaInaura


<!-- Update From Qiita API -->



# 公開日時

2019-12-09

Discussion