# พื้นฐาน Ruby (Ruby on Rails) > ตัวแปร, ชนิดข้อมูล, control flow, เมท็อด, blocks, procs, lambdas - 25 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Ruby on Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions.md) ## 1. ความแตกต่างระหว่างตัวแปร local และตัวแปร instance ใน Ruby คืออะไร? **คำตอบ** ตัวแปร local เริ่มต้นด้วยตัวอักษรพิมพ์เล็กหรือ underscore และเข้าถึงได้เฉพาะภายในขอบเขตของมัน (method หรือ block) เท่านั้น ส่วนตัวแปร instance เริ่มต้นด้วย @ และเข้าถึงได้จากทุก method ของออบเจกต์ โดยคงอยู่ตลอดอายุของ instance การแยกแยะนี้เป็นพื้นฐานสำคัญสำหรับการจัดการ state ในออบเจกต์ Ruby ## 2. จะประกาศค่าคงที่ใน Ruby อย่างไร และมีหลักการตั้งชื่ออย่างไร? **คำตอบ** ใน Ruby ค่าคงที่จะถูกประกาศโดยใช้ชื่อที่ขึ้นต้นด้วยตัวอักษรพิมพ์ใหญ่ ตามหลักการตั้งชื่อ ค่าคงที่จะเขียนในรูปแบบ SCREAMING_SNAKE_CASE (เช่น MAX_SIZE = 100) Ruby จะแสดง warning หากค่าคงที่ถูกแก้ไข แต่ไม่ได้ป้องกันการแก้ไขเหมือนภาษาอื่น ## 3. ผลลัพธ์ของนิพจน์ 5 / 2 ใน Ruby คืออะไร และจะได้ผลลัพธ์ทศนิยมอย่างไร? **คำตอบ** ใน Ruby การหารระหว่างจำนวนเต็มสองตัว (Integer) จะคืนค่าเป็นจำนวนเต็ม (5 / 2 = 2) เพื่อให้ได้ผลลัพธ์ทศนิยม ตัวถูกดำเนินการอย่างน้อยหนึ่งตัวต้องเป็น Float: 5.0 / 2 หรือ 5 / 2.0 หรือ 5.to_f / 2 กฎนี้เป็นไปตามหลักการหารจำนวนเต็มที่มีอยู่ในหลายภาษา ## มีอีก 22 คำถาม - ความแตกต่างระหว่าง Symbol (:name) และ String ("name") ใน Ruby คืออะไร? - การแทรกค่าในสตริง (string interpolation) ใน Ruby ทำงานอย่างไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Ruby on Rails อื่นๆ - [การเขียนโปรแกรมเชิงวัตถุใน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-oop.md): 20 คำถาม, Junior - [พื้นฐาน Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-fundamentals.md): 18 คำถาม, Junior - [Routing & Controllers](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/routing-controllers.md): 22 คำถาม, Junior - [พื้นฐาน ActiveRecord](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-basics.md): 25 คำถาม, Junior - [Views และ ERB Templates](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/views-erb-templates.md): 20 คำถาม, Junior - [การเชื่อมโยงของ ActiveRecord](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-associations.md): 24 คำถาม, Mid-Level - [การสอบถาม ActiveRecord ขั้นสูง](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-queries.md): 28 คำถาม, Mid-Level - [ฟอร์ม Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-forms.md): 20 คำถาม, Mid-Level - [การยืนยันตัวตนและการอนุญาต](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/authentication-authorization.md): 22 คำถาม, Mid-Level - [Asset Pipeline สมัยใหม่และ frontend](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-asset-pipeline.md): 18 คำถาม, Mid-Level - [โหมด API ของ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-api-mode.md): 20 คำถาม, Mid-Level - [การทดสอบด้วย RSpec](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-testing-rspec.md): 24 คำถาม, Mid-Level - [ActiveJob & Background Jobs](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-job-background-jobs.md): 20 คำถาม, Mid-Level - [ActionCable & WebSockets](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/action-cable-websockets.md): 18 คำถาม, Mid-Level - [ActionMailer](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/action-mailer.md): 18 คำถาม, Mid-Level - [ActiveStorage](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-storage.md): 20 คำถาม, Mid-Level - [กลยุทธ์การ Caching](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/caching-strategies.md): 20 คำถาม, Mid-Level - [การ Migration ขั้นสูง](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/database-migrations-advanced.md): 20 คำถาม, Mid-Level - [Rails Engines และแอปแบบโมดูลาร์](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-engines-modular-apps.md): 18 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/performance-optimization.md): 26 คำถาม, Senior - [Design Patterns ใน Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-design-patterns.md): 22 คำถาม, Senior - [เมตาโปรแกรมมิงใน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-metaprogramming.md): 20 คำถาม, Senior - [ความปลอดภัยของ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-security.md): 22 คำถาม, Senior - [GraphQL กับ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/graphql-rails.md): 20 คำถาม, Senior - [การดีพลอยและโปรดักชัน](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-deployment-production.md): 20 คำถาม, Senior - [Monitoring & Logging](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/monitoring-logging.md): 20 คำถาม, Senior - [กลยุทธ์การอัปเกรด Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-upgrade-strategies.md): 18 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-basics