Difference between classes and constants in ruby w.r.t const_get?

Why does const_get() return the actual class, even though const_get is a method that is supposed to return a constant of the given name.
Does Ruby just store classes similarly to constants, or is it something else?

Source: ruby

1 Comment

  1. Digin Dominic

    In ruby, classes are merely instances of class Class.

    klass = Class.new do
    # class definition

    In this way, you’ll get an anonymous class. If you assign it to a constant,

    MyClass = Class.new do
    # class definition

    Then you just give the class a name, MyClass.

    The standard ruby way to define a class is only a syntactic sugar!


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.