DEV Community

Thinh Tran
Thinh Tran

Posted on

[ Boxes of Ruby ] The Starter Way to Manage Living Information in Applications

Previous chapter: [ Introduction to Ruby ]

So, we pop up the calculator app, push some buttons to input some information related to our living situations, and expect some output results. What's really happened behind the screen?

For most of us who are using a tech gadget in daily life, the common reason behind the whole world of technology is information. I mean what we're truly seeking in the functions of the gadgets is always the ability to take care of our living information in various aspects.

Some may want a gadget to help simplifying calculations that ones need to perform on a living information block. Some may want a gadget to help updating information of the world around the Sun. And in our current time these all tasks may be taken of by a single device like a phone or a laptop.

The Box of Information

It's hard to guess what's really happened behind the screen when we've not seen the Hello, World! app. But, later then, things are simplified down as just a single tiny box which can enclose almost every kind of information that we put there.

~/Desktop/main.rb

main = Proc.new { |box|
   puts "Hello, #{box}!"
}

main.call 2023
Enter fullscreen mode Exit fullscreen mode

CMD|Terminal.io

ruby main.js

Hello, 2023!
Enter fullscreen mode Exit fullscreen mode

So, to write code to create a program may have the slimmest meaning as we're gonna create boxes after boxes to transmit and manipulate all kinds of information.

Basic Types of Information

It's all started from our daily life and all the tasks that our mind has to engaged in. By updating and analyzing information, our mind is generally dealing with some words, numbers, and sometimes logical identification results.

~/Desktop/main.rb

main = Proc.new { |name, age, online|
   if online
      puts "Hello, World!"
      puts "I'm #{name} and #{age} times cycled around the Sun."
   else
      puts "You're offline now."
      puts "Go online first."
   end
}

main.call "Semi-Art", 32, true
Enter fullscreen mode Exit fullscreen mode

CMD|Terminal.io

ruby main.js

Hello, World!
I'm Semi-Art and 32 times cycled around the Sun.
Enter fullscreen mode Exit fullscreen mode

Structured Types for Convenience

Things like the main in the example code is also a box. We've used it to store an instance of a procedure at first. And then we've use the dot notation . to make a call using the procedure.

The call itself is a box, too. It stored the core definition of the procedure instance that we can apply to the listed pieces of information there. What a magical box.

It also means that we can use one box to wrap some others to represent things in our nature living world and things in software environment. And then that one box which enclosed others is now called a structured type for convenience to express our mind into the code.

Nope. We're not gonna make an example or the structured one here. These all are just to make our mind more comfortable with the unknown elements of the code. Just call everything box until we start specify things by their own convenience.

Technical Terms

Since we're learning technical stuff, then technical terms are just necessary as slang words in our local living. And we'll just settle these words at the end of each posts to use in the next.

[ Basic Types ]

  • number - a technical name of the type to represent information in numbers.
  • string - a technical name of the type to represent text information.
  • boolean - a technical name of the type to represent logical identification results as true or false.
  • nil - a technical name of the type to represent the absence of information as nil.

[ Some Boxes ]

  • variable - a box which is created on the flow of a series of statements anywhere in the code.
  • parameter - a box which is created in the definition of a code block to take input information when the block gets called.
  • object - a box which enclosed other boxes then can be accessed using dot notation .

See you in the next chapter: [ Classes of Ruby ]

Top comments (0)