ruby initialize method - purpose of initialize arguments

ruby initialize method - purpose of initialize arguments

Im a bit confused on the initialize method. I understand that it is automatically called when you do Person.new and you add the arguments to it like Person.new("james"). What I dont understand is, why would you have instance variables in your initialize method that are not an used as an argument also. Is it so you can use them later on after the instance has been created? See below. What reason is there to have @age in the initialize method but not as an argument. thanks.

Im a bit confused on the initialize method. I understand that it is automatically called when you do Person.new and you add the arguments to it like Person.new("james"). What I dont understand is, why would you have instance variables in your initialize method that are not an used as an argument also. Is it so you can use them later on after the instance has been created? See below. What reason is there to have @age in the initialize method but not as an argument. thanks.

class Person

attr_accessor :name, :age

def initialize(name) @name = name @age = age end


ruby oop

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

OOP course content in C# | OOP in C# Part-1

LIKE | COMMENT | SHARE | SUBSCRIBE OOP(object oriented programming) Course content........ Blog : http://aspdotnetexplorer.blogspot.com Like our page - https...

Basic OOP with Class and Objecct | OOP in C# Part-3

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Class and Object . Blog : http://aspdotnetexplorer.blogspot.com Like our page - h...

Properties in C# | OOP in C# Part-7

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about properties in c#. Blog : http://aspdotnetexplorer.blogspot.com Like our page - ht...

Constructor in C# | OOP in C# Part-9

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Constructor. Blog : http://aspdotnetexplorer.blogspot.com Like our page - https:/...

Class and Object in C# | OOP in C# Part-2

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Class and Object. Blog : http://aspdotnetexplorer.blogspot.com Like our page - ht...