Fallen in love with Ruby 💖

Ajithkumar P S - Dec 17 '23 - - Dev Community

Hello all rubyists 👋, In this blog post I will share what made me to fall in love with Ruby programming language. I'm not the expert still just sharing my views here.

Initially I have started my career in web development as a PHP Developer. 🐘 -> 💎

As the docs says Ruby A Programmer's Best Friend. It offers more readability and elegant syntax that is easy to read and write not very cryptic see in action.

PHP Example code 🐘:

<?php
class Student {
    public $name;
    public $age;
    public $grade;

    function __construct($name, $age, $grade) {
        $this->name = $name;
        $this->age = $age;
        $this->grade = $grade;
    }

    function display() {
        echo "Name: " . $this->name . "\n";
        echo "Age: " . $this->age . "\n";
        echo "Grade: " . $this->grade . "\n";
    }
}

$student1 = new Student("John", 18, "A");
$student2 = new Student("Jane", 19, "B");

echo "Student 1:\n";
$student1->display();

echo "\nStudent 2:\n";
$student2->display();
?>


Enter fullscreen mode Exit fullscreen mode

Ruby Example code 💎:

class Student
  attr_accessor :name, :age, :grade

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

  def display
    puts "Name: #{@name}"
    puts "Age: #{@age}"
    puts "Grade: #{@grade}"
  end
end

student1 = Student.new("John", 18, "A")
student2 = Student.new("Jane", 19, "B")

puts "Student 1:"
student1.display

puts "\nStudent 2:"
student2.display

Enter fullscreen mode Exit fullscreen mode

For me the ruby version looks cool and feels more readable than PHP and easy to understand with less lines of code as well. Not only readability there is often more than one way of doing things in Ruby. If you know some other interesting stuffs in Ruby let me know in comments section. Thanks for reading 🤝.

. . . . . . . . .
Terabox Video Player