This is functionally equivalent to regular class definition, but more explicit.

By convention, classes are referenced by constants in Ruby. This is why we're assigning
the object returned by Class.new to Customer constant, but we can assign it to
a regular variable as well. On the other hand, if you don't use a constant in a
regular class definition, you will get an error:

SyntaxError: class/module name must be CONSTANT

Now, why would you ever want to use Class.new over regular class definition? Let's
look at creating a custom error class (for good reason, custom error classes should
inherit from StandardError):

classCustomerError<StandardErrorend# This usually gets shortened as:classCustomerError<StandardError;end

You can pass in an argument to Class.new to specify the super class for the class
you're creating. With this in mind, you can define CustomerError more elegantly:

CustomerError=Class.new(StandardError)

This is such a minor improvement, but a good use-case nonetheless. Another use-case
for Class.new might be in testing. If you need to define classes only to be used
by your tests, you don't want to pollute the global namespace with the test class
constants. You can use Class.new to store the test classes in local or instance
variables.

Use Struct

Struct is available as part of Ruby's standard library, and you don't need to
require anything to use it. Struct lets you create classes for data container
objects without any boilerplate:

Customer=Struct.new(:full_name,:card_type,:card_number)

This has all the features of Customer class we created with regular class
definition as well as using Class.new above. In addition, the customer objects
will have equality as per value object
semantics:

Conclusion

In Ruby, you can create classes using the class keyword (class definition),
Class.new, and Struct. Although you would use regular class definition
in the vast majority of cases, Class.new and Struct would sometimes come
in handy if you know how to use them.