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
    end

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

    MyClass = Class.new do
    # class definition
    end

    Then you just give the class a name, MyClass.

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

    Reply

Leave a Reply