coding for food

[Ruby] class 정리

silveryen 2022. 9. 2. 10:57

object은 데이터 타입의 structure 이다. 

class Dog
  # has a tail
  # has a name
  # has a breed
  # can bark
  # can drink water from bowl
end
fido = Dog.new #=> fido는 Dog class의 instance(사례)이다.
  • Class: 커스텀한 데이터 structure를 위한 템플랫이다.
  • Object: An instance of a class. This would be Fido himself. Fido is a dog. Or, more specifically, fido is a Dog.
"fire extinguisher".class
#=> String

“fire extinguisher”는 instance of the String class이다.