author avatar

nived.hari

Thu Feb 20 2025

In Ruby, attr_reader automatically creates a getter method for instance variables, making code cleaner and more concise. Instead of writing:


def some_number
  @some_number
end


You can simply use:


attr_reader :some_number


This makes attributes read-only while keeping the class lightweight

#ruby #CU6U0R822