What is a class?

Technology CommunityCategory: RubyWhat is a class?
VietMX Staff asked 3 years ago

Classes hold data, have methods that interact with that data, and are used to instantiate objects.

class WhatAreClasses
  def initialize
    @data = "I'm instance data of this object. Hello."
  end

  def method
    puts @data.gsub("instance", "altered")
  end
end

object = WhatAreClasses.new
object.method
 #=> I'm altered data of this object. Hello.