
Ruby Object-Oriented Programming
Classes, modules, inheritance, mixins, attr_accessor, self, basic metaprogramming
1How to define a class in Ruby?
How to define a class in Ruby?
Jawaban
In Ruby, a class is defined with the class keyword followed by the class name (CamelCase by convention) and ends with end. The initialize method serves as the constructor and is automatically called when creating a new instance with Class.new. Instance variables (prefixed with @) store the state of each object.
2What is the role of the initialize method in Ruby?
What is the role of the initialize method in Ruby?
Jawaban
The initialize method is the constructor in Ruby. It is automatically called when a new object is created via Class.new. It allows initializing instance variables and setting up the initial state of the object. Unlike other languages, the constructor is not named after the class but is always called initialize.
3What is the difference between attr_reader, attr_writer and attr_accessor?
What is the difference between attr_reader, attr_writer and attr_accessor?
Jawaban
These three class methods automatically generate accessors. attr_reader creates only a getter (read), attr_writer creates only a setter (write), and attr_accessor creates both at once. This avoids manually writing repetitive getter/setter methods, making the code more concise and readable.
How does class inheritance work in Ruby?
What is the difference between a module and a class in Ruby?
+17 pertanyaan wawancara
Topik wawancara Ruby on Rails lainnya
Ruby Basics
Rails Fundamentals
Routing & Controllers
ActiveRecord Basics
Views & ERB Templates
ActiveRecord Associations
Advanced ActiveRecord Queries
Rails Forms
Authentication & Authorization
Modern Asset Pipeline & Frontend
Rails API Mode
Testing with RSpec
ActiveJob & Background Jobs
ActionCable & WebSockets
ActionMailer
ActiveStorage
Caching Strategies
Advanced Migrations
Rails Engines & Modular Apps
Performance Optimization
Rails Design Patterns
Ruby Metaprogramming
Rails Security
GraphQL with Rails
Deployment & Production
Monitoring & Logging
Rails Upgrade Strategies
Kuasai Ruby on Rails untuk wawancara berikutnya
Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.
Mulai gratis