{"id":20371562,"url":"https://github.com/atulkamble/ruby","last_synced_at":"2025-09-02T11:33:27.482Z","repository":{"id":245442293,"uuid":"818262654","full_name":"atulkamble/ruby","owner":"atulkamble","description":"Basic Ruby Codes","archived":false,"fork":false,"pushed_at":"2024-08-14T07:56:26.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T10:48:29.267Z","etag":null,"topics":["aws","ec2","ruby","ruby-programming-language"],"latest_commit_sha":null,"homepage":"https://youtu.be/gs0SG8brB-s?feature=shared","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atulkamble.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-21T13:01:36.000Z","updated_at":"2024-08-14T08:30:53.000Z","dependencies_parsed_at":"2024-06-22T05:52:21.904Z","dependency_job_id":null,"html_url":"https://github.com/atulkamble/ruby","commit_stats":null,"previous_names":["atulkamble/ruby"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atulkamble%2Fruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atulkamble","download_url":"https://codeload.github.com/atulkamble/ruby/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241916682,"owners_count":20041960,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","ec2","ruby","ruby-programming-language"],"created_at":"2024-11-15T01:08:31.859Z","updated_at":"2025-09-02T11:33:27.450Z","avatar_url":"https://github.com/atulkamble.png","language":"Ruby","readme":"# Ruby Practice\n```\nsudo yum install git -y\nsudo yum install ruby -y \nruby --version\ngit clone https://github.com/atulkamble/ruby.git\ncd ruby \n```\n\n## Overview\nThis repository contains a series of practice programs designed to help users get started with Ruby programming. The examples cover fundamental concepts such as basic syntax, variables, conditionals, loops, arrays, hashes, methods, classes, file operations, and more.\n\n## Prerequisites\n\nTo launch and connect to an EC2 instance, follow these steps:\n\n### 1. Launch an EC2 Instance\n\n1. **Sign in to AWS Management Console**\n   - Go to the [AWS Management Console](https://aws.amazon.com/console/) and log in with your credentials.\n\n2. **Navigate to EC2 Dashboard**\n   - In the AWS Management Console, search for \"EC2\" and click on \"EC2\" to open the EC2 Dashboard.\n\n3. **Launch an Instance**\n   - Click on the “Launch Instance” button.\n\n4. **Choose an Amazon Machine Image (AMI)**\n   - Select an AMI from the list. For example, you can choose an Ubuntu Server, Amazon Linux, or any other preferred operating system.\n\n5. **Choose an Instance Type**\n   - Select an instance type based on your needs (e.g., `t2.micro` for a free tier option). Click “Next: Configure Instance Details”.\n\n6. **Configure Instance**\n   - Configure the instance settings such as the number of instances, network, and subnet. Click “Next: Add Storage” when done.\n\n7. **Add Storage**\n   - Adjust the size and type of storage if needed. Click “Next: Add Tags”.\n\n8. **Add Tags**\n   - Optionally, add tags to help identify your instance. For example, you might add a Name tag with a value like “MyEC2Instance”.\n\n9. **Configure Security Group**\n   - Create a new security group or select an existing one. Ensure that you allow SSH (port 22) for accessing your instance. You can also allow HTTP (port 80) or HTTPS (port 443) if needed.\n\n10. **Review and Launch**\n    - Review your settings and click “Launch”.\n\n11. **Select a Key Pair**\n    - You will be prompted to select an existing key pair or create a new one. Download the key pair (`.pem` file) and keep it safe as you'll need it to connect to your instance.\n\n12. **Launch the Instance**\n    - Click “Launch Instances” to start your EC2 instance. You will be taken to the “Instances” page where you can view the status of your new instance.\n\n### 2. Connect to Your EC2 Instance\n\n1. **Locate Your Instance**\n   - Go to the EC2 Dashboard and select “Instances” to see the list of your instances.\n\n2. **Get the Public IP Address**\n   - Find your instance in the list and note its Public IP address or Public DNS name.\n\n3. **Connect via SSH**\n   - Open a terminal on your local machine.\n\n   Use the following command to connect to your instance, replacing the placeholders with your actual key file, user name, and IP address:\n   ```bash\n   ssh -i /path/to/your-key.pem ec2-user@your-ec2-public-ip\n   ```\n   - For Ubuntu instances, use:\n     ```bash\n     ssh -i /path/to/your-key.pem ubuntu@your-ec2-public-ip\n     ```\n   - Ensure your key file has the correct permissions:\n     ```bash\n     chmod 400 /path/to/your-key.pem\n     ```\n\n4. **Accept the Connection**\n   - The first time you connect, you may be prompted to accept the host’s fingerprint. Type “yes” to continue.\n\n5. **Access Your Instance**\n   - You should now be connected to your EC2 instance and can begin running commands on it.\n\n### Troubleshooting\n\n- **Security Group Rules:** Ensure the security group associated with your instance has the correct inbound rules (e.g., SSH access on port 22).\n\n- **Key Pair:** Ensure you use the correct `.pem` file associated with the instance and that it has the correct permissions.\n\n- **Instance State:** Ensure the instance is in the “running” state and not in any other state like “stopped” or “terminated”.\n\nIf you encounter any issues, double-check your security group settings, key pair, and instance configuration.\n\n### Ruby Installation\n\nEnsure you have Ruby installed on your system. Install Ruby using the following command:\n```bash\nsudo yum install ruby -y\n```\nVerify the installation:\n```bash\nruby --version\n```\n\n## Repository Setup\n\n1. **Clone the Repository**\n   Clone the repository to your local machine:\n   ```bash\n   git clone https://github.com/atulkamble/ruby.git\n   cd ruby\n   ```\n\n## Practice Steps\n\n1. **Create and Edit Ruby Files**\n\n   Navigate to the `ruby` directory and create file, edit it and run:\n   ```bash\n   cd ruby\n   touch hello_world.rb\n   sudo nano hello_world.rb\n   ruby hello_world.rb\n   ```\n\n2. **Explore and Modify Files**\n   - Create and run various Ruby files, such as `02_sum.rb`, etc.\n   - Use `nano` or another text editor to modify these files as needed.\n   - Example commands:\n     ```bash\n     touch 02_sum.rb\n     sudo nano 02_sum.rb\n     ruby 02_sum.rb\n     ```\n\n3. **File Operations**\n   - Move and rename files:\n     ```bash\n     mv hello_world.rb 01_hello_world.rb\n     ```\n   - List files and directories:\n     ```bash\n     ls\n     ```\n   - Remove files:\n     ```bash\n     rm 04_loops.rb\n     ```\n\n## Example Ruby Programs\n\n### 1. Hello World\nPrints a simple \"Hello, World!\" message.\n```ruby\n# hello_world.rb\nputs \"Hello, World!\"\n```\n\n### 2. Variables and Basic Operations\nDemonstrates basic arithmetic operations and variable usage.\n```ruby\n# variables.rb\na = 10\nb = 20\nsum = a + b\n\nputs \"The sum of #{a} and #{b} is #{sum}\"\n```\n\n### 3. Conditional Statements\nUses `if` statements to evaluate conditions.\n```ruby\n# conditionals.rb\nnumber = 7\n\nif number \u003e 0\n  puts \"#{number} is positive\"\nelsif number \u003c 0\n  puts \"#{number} is negative\"\nelse\n  puts \"#{number} is zero\"\nend\n```\n\n### 4. Loops\nIllustrates different types of loops.\n```ruby\n# loops.rb\n# Using a while loop\ni = 1\nwhile i \u003c= 5\n  puts \"Iteration #{i}\"\n  i += 1\nend\n\n# Using a for loop\nfor i in 1..5\n  puts \"Iteration #{i}\"\nend\n```\n\n### 5. Arrays\nDemonstrates array operations and iteration.\n```ruby\n# arrays.rb\narr = [1, 2, 3, 4, 5]\n\n# Accessing elements\nputs \"First element: #{arr[0]}\"\n\n# Iterating through an array\narr.each do |element|\n  puts \"Element: #{element}\"\nend\n```\n\n### 6. Hashes\nShows how to use hashes for storing key-value pairs.\n```ruby\n# hashes.rb\nperson = {\n  name: \"John\",\n  age: 30,\n  city: \"New York\"\n}\n\n# Accessing values\nputs \"Name: #{person[:name]}\"\nputs \"Age: #{person[:age]}\"\nputs \"City: #{person[:city]}\"\n```\n\n### 7. Methods\nDefines and calls methods in Ruby.\n```ruby\n# methods.rb\ndef greet(name)\n  return \"Hello, #{name}!\"\nend\n\nputs greet(\"Alice\")\nputs greet(\"Bob\")\n```\n\n### 8. Classes and Objects\nCreates a class and uses its instances.\n```ruby\n# classes.rb\nclass Person\n  attr_accessor :name, :age\n\n  def initialize(name, age)\n    @name = name\n    @age = age\n  end\n\n  def introduce\n    \"Hello, my name is #{@name} and I am #{@age} years old.\"\n  end\nend\n\nperson1 = Person.new(\"Alice\", 25)\nputs person1.introduce\n\nperson2 = Person.new(\"Bob\", 30)\nputs person2.introduce\n```\n\n### 9. Reading from a File\nReads content from a file and prints it.\n```ruby\n# read_file.rb\nfile_name = \"example.txt\"\n\nif File.exist?(file_name)\n  File.open(file_name, \"r\") do |file|\n    file.each_line do |line|\n      puts line\n    end\n  end\nelse\n  puts \"File not found.\"\nend\n```\n\n### 10. Writing to a File\nWrites content to a file.\n```ruby\n# write_file.rb\nfile_name = \"output.txt\"\n\nFile.open(file_name, \"w\") do |file|\n  file.puts \"This is a sample text.\"\n  file.puts \"Written to the file.\"\nend\n\nputs \"Content written to #{file_name}\"\n```\n\nThese practice programs cover a broad range of Ruby programming concepts. Modify and extend these examples to deepen your understanding of Ruby and enhance your programming skills.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatulkamble%2Fruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatulkamble%2Fruby/lists"}