# ประเภทข้อมูลต่างๆ

ก่อนที่จะไปต่อกันเรื่องการใช้งาน จะขออธิบายกันเรื่องประเภทต่างๆ ของข้อมูลในภาษา Ruby ก่อน ทั้งนี้จะรวมถึงประเภทที่ได้กล่าวถึงไปแล้วก่อนหน้านี้ เช่นตัวเลขและสตริง เพื่อเป็นการทบทวนความรู้ไปด้วย

{% hint style="info" %}
ประเภทข้อมูลทุกอย่างสามารถเก็บไว้ใน[ตัวแปร](/courses/ruby/variables.md) เพื่อนำมาใช้ซ้ำ หรือเปลี่ยนค่าในภายหลังได้
{% endhint %}

### ตัวเลข

ตัวเลขทั้งแบบจำนวนเต็ม (**Integer** หรือ **Fixed**) และตัวเลขแบบทศนิยม (**Float** หรือ **Double** หรือ **Decimal**) ใช้ในการคำนวณทางคณิตศาสตร์ต่างๆ

### สตริง

สตริง หรือชุดขักขระ ไว้เก็บตัวอักษร ครอบด้วย `" "` หรือ `' '`

### ค่าความจริง / เท็จ (Boolean : บูเลียน)

Boolean เป็นค่าความจริงหรือเท็จตามแบบตรรกศาสตร์ ซึ่งแทนด้วย

* `true` (จริง)
* `false` (เท็จ

มักใช้ในการเขียนเงื่อนไขเช่น `if` / `else` ซึ่งจะสอนในบทถัดไป

### อาร์เรย์ (Array)

ใช้เก็บข้อมูลแบบกลุ่ม เช่นรายซื่อของคนหลายๆ คน หรือเก็บค่าสีต่างๆ เป็นต้น

### แฮช (Hash)

ใช้เก็บข้อมูลเป็นแบบ Key-Value เช่น `{name: "Ruby", version: 3.0}` คือข้อมูลที่ `name` ชี้ไป `"Ruby"` , `version` ชี้ไป `3.0`

### nil

`nil` เปรียบเสมือน "ว่างเปล่า" หรือ "ไม่มีข้อมูล" (ภาษาอื่นๆ มักใช้คำว่า `null`)

ในบทหน้าจะเริ่มลงรายละเอียดจากข้อมูลประเภทบูเลียน และวิธีการใช้งานกับการเขียนเงื่อนไข `if-else`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.monosor.dev/courses/ruby/data-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
