LEARNING RUBY: PART 2, NUMBERS and MATHS

Welcome brothers and sisters. So, we've started a new series on ruby and this is my third post on it. Now lets take a summary of what we have studied previously!

> puts
>comments
>shebang (#! if you have searched it on the internet!)
Today, we'll be doing mathematics!

MATH!

Lets take a small review of symbol used in math.
plus +, minus-, multiply (*),divide / and many more.
Now just like we did it last time we're going to do the same.

  1. Opening text editor
  2. Setting up the shebang.
  3. Using comments if you want to!

And here is what should look like.

Now after that, type:
puts "I will now count my chickens:"

puts "Hens #{25 + 30 / 6}"
puts "Roosters #{100 - 25 3 % 4}"

puts "Now I will count the eggs:"

puts 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6

puts "Is it true that 3 + 2 < 5 - 7?"

puts 3 + 2 < 5 - 7

puts "What is 3 + 2? #{3 + 2}"
puts "What is 5 - 7? #{5 - 7}"

puts "Oh, that's why it's false."

puts "How about some more."

puts "Is it greater? #{5 > -2}"
puts "Is it greater or equal? #{5 >= -2}"
puts "Is it less or equal? #{5 <= -2}"
And it will look something like this.

And just save it with whatever name you want, give it permissions to execute and you are done. Now you may have noticed the #{} inside the code. What it will do? Any theories regarding this? Check it out by executing it! Also we have used inequalities symbols inside the code like >= and <= and even this >, <. Using these symbols will give you answers in true and false. So execute the code and see what you'll get.

A SIDE NOTE! You do not have to use math functions inside the "" or strings, otherwise they will be recognized as string themselves. Try it out, what will happen!

STUDY DRILL

For the time being, you can do these things to strengthen your skill.

  1. Search on internet for the #{} function.
  2. Modify your code to use more of these #{} functions and comments.
  3. Write at least 3 more such types of codes.

FEEDBACK!

I know these things look boring but every person who is a hacker right now has done all such things, trust me!! I'm not like other persons who posts stuffs like Hey, check this post! its about hacking fb. So I'm not a Santa Claus who will give you ready-made tools as a Christmas gift. Ain't gonna happen! I want you to master your skills not playing with the toys.

So, if you like my post, please tell me in the comments and if you don't, give me feedback.
Thank you very much!!! I'm:

>>>DUSTY WORLD///

Our Best Hacking & Security Guides

New Null Byte posts — delivered straight to your inbox.

1 Response

Cool post! Thanks for writing

Share Your Thoughts

  • Hot
  • Active