• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Learning Ruby : For Beginners

By Abhishek Ghosh June 17, 2023 9:11 am Updated on June 17, 2023

Learning Ruby : For Beginners

Advertisement

Ruby is a beautiful language which can be written like poems and it is difficult to run an exploit. In other words, Ruby is object-oriented, reflective, general-purpose, dynamic programming language which is secure. Julia, Swift, Rust etc newer languages like Ruby. Due to the initial lack of English documentation, the language spread mainly in the Japanese-speaking world, where it has since become more popular than its Western counterpart Python. It wasn’t until the advent of the Ruby on Rails web framework and the need for fast web development that Ruby became widespread in the Western world.

During the development of Ruby, the focus was on the uniformity and readability of the source code. This applies in particular to conventions for naming variables and methods as well as a very uniform and consistent syntax. In Ruby, the advantages of object-oriented and functional programming are combined; this makes it possible to describe and solve many problems very easily.

There is a large number of available libraries that, in conjunction with RubyGems, allow you to avoid having to solve common problems yourself through easy availability. This means that a large number of applications can be developed in Ruby, from console scripts and graphical applications to network and Internet applications.

Advertisement

---

Learning Ruby For Beginners

 

Installation of Ruby

 

Windows: Open Ubuntu bash, run apt-get install ruby command.

Linux: Open the terminal, run apt-get install ruby command or yum install ruby ruby-devel

MacOS: Under MacOS X, a Ruby interpreter is installed with the operating system. However, you can install the latest Ruby managed via Homebrew (it sounds sarcastic though, Homebrew is written in Ruby).

Open iTerm2 (with homebrew installed), run brew install ruby

Optionally, in ~/.bash_profile (or .profile or .zshrc) add the following line:

Vim
1
export PATH=/usr/local/Cellar/ruby/2.3.1p112/bin:$PATH

2.3.1p112 is the version of Ruby, which can be found by”

Vim
1
ruby --version

You can source the file to reload the settings:

Vim
1
source ~/.bash_profile

 

Learning Ruby : Chapter 1

 

Type irb on terminal or bash or iTerm2, whatever you use. irb means interactive Ruby. Type 2+4 and hit enter. The basic calculations can be directly done on Ruby.

puts in Ruby is the print in other languages. But it is not like a dumb print of other languages. Type:

Vim
1
puts "Hello World"

Hit Enter. You’ll get the output:

Vim
1
2
Hello World
=> nil

Now, run:

Vim
1
puts "Hello World"; 24*365

You’ll get the output:

Vim
1
2
Hello World
=> 8760

Now, run:

Vim
1
"Hello World"

You’ll get the output:

Vim
1
=> "Hello World"

Now, run:

Vim
1
"Hello World"; 24*365

What will be the output?

OK. Now do this:

Vim
1
24*365; "Hello World"

What do you think?

# is used to add comments to your code in Ruby or to insert a dynamic value with #{thing}.
=begin, =end is used to indicate multi-line comments.

Now, type these lines one by one and hit Enter:

Vim
1
2
3
def hi
puts "Hello World!"
end

This means hi is related to the string Hello World!. If you type hi or hi() and hit Enter, it will return you Hello World!. def in this context is the definition of the method, hi is the name of the method. Now if this hi defined a complex calculation, we could easily grab the value by calling hi.

Time.now prints the present time. We can run:

Vim
1
puts "I have #{24+300/6} cents in my PayPal account at" #{Time.now}

Without , or ; before Time.now there will be syntax error. Now type exit to exit the irb and run:

Vim
1
nano test.rb

Paste this content:

Vim
1
2
3
4
5
6
7
if 1 > 2
  puts "1 is greater than 2"
elsif 2 > 1
  puts "1 is not greater than 2"
else
  puts "1 is equal to 2"
end

Then execute the script:

Vim
1
2
chmod +x test.rb
ruby test.rb

This ends the first chapter.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Learning Ruby : For Beginners

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • OpenShift OctoPress Auto install Script

    OpenShift OctoPress Auto install Script is an Advanced Script to Run OctoPress on Free OpenShift PaaS Practically Without Any Knowing Ruby or Git.

  • Which Programming Language is the Best for a Tech Student

    You’ve heard about the importance of education. Most likely, you’ve been hearing it throughout your childhood. You should study to acquire the profession that will help you to land the job of your dream. Moreover, every ten to twenty years there was that specific profession that everybody wanted to acquire. Things do change with time, […]

  • Install RVM on Rackspace Cloud Server (Ubuntu, PVHVM)

    Here is a step by step guide for the beginners on how to install RVM on Rackspace Cloud Server running Ubuntu 14.04, PVHVM version for Rails.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy