In the first sentence, you create an anonymous class with the superclass String
:
my_str.class.superclass
But this is not the essence of your current question :)
An instance is an object of a certain class: String.new() # creates instance of class String
. Instances have classes (String.new()).class #=> String
. All classes are instances of the class Class
: String.class # => Class
. Class instances also have the superclass
class - which they inherit.
An instance method is a method that you can call on an instance of an object.
"st ri ng".split
A class method in Ruby is a general term, for example, for methods of the Class
class (any class).
String.try_convert("abc")
Read more about instance and class methods in this article .
source share