Ruby Course – Codemeets– 02

November 26, 2020

Ruby programming lesson 2. Today we going to learn more about Ruby. In this tutorial, we will focus on Variable, Strings, Numbers, and Operations. It can provide extensive knowledge.

Use Variable

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.launchschool.com

Now you know what is variable, let’s use it Ruby Programming

character_name = "jenny"
character_age = "23"
puts "my name is "+ character_name
puts "my age is "+ character_age

This Code output is My Name is jenny my age is 23. you can try this code in your pc.

Working with Strings Ruby Programming

Threads are traditionally alphabetical. Now you can see how it works. see below table and get idea about ruby strings.

Phone = "Apple Iphone"
CodeOutput
puts Phone.upcaseAPPLE IPHONE
puts Phone.downcaseapple iphone
puts Phone.stripApple Iphone
puts Phone.length12
puts Phone.include?"Apple"true
puts Phone.include?"cake"false
puts Phone.[3,5]le Ip
puts "hp".upcase()HP

Work with Strings

Working With Numbers

Every computer language uses numbers in particular. This is because it allows you to easily control the data. let me show you how to work with numbers in Ruby.

SyntaxCode
puts -5.43215-5.43215
puts 5+914
puts 5/90
puts 2*36
puts 2**38
puts 10%31
puts 5-23

Operations & Math in Ruby Programming

In mathematics, we use different operations, i.e. maximum value, square root, fall. They are also used differently in programming. The following example will give you a broader understanding.

Operations
num = 30.67
CodeOutput
puts num.abs()30.67
puts num.round()30
puts num.ceil()31
puts num.floor()30

Operations

Math

it is a hard mathematics part but using ruby we can do it easy. see below table.

SyntaxOutput
puts Math.sqrt (2)1.4142135623730951
puts Math.log (2)0.6931471805599453

Math

Now you have developed some knowledge about Ruby. Try typing this code on your computer as well. Practice

Output

Thank for all!

More Ruby ClickHere!

See you Next Ruby Lesson Soon!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »