Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • entries
    15
  • comments
    11
  • views
    14,483

Learning Ruby -- Lesson 2: Objects, Objects, Objects aka Ruby's Data Types

Sign in to follow this  
kellessdee

586 views

Lesson 2: Objects, Objects, Objects aka Ruby's Data Types

 

You've probably heard people talk about "object-oriented" languages or programming (and you may even know what this means already). Well then, what is an object-oriented language? It simply refers to a programming language that is based around the object model and it's concepts. So, it's probably better to start at: What is an object?

 

Well, this may seem cheesy, but:

 

ob·ject/'äbj?kt/

Noun: A material thing that can be seen and touched. (google search)

 

So how does this apply to computers?

Now, you may have gone ahead and googled the answer for yourself (if you did, I applaud you for doing so. Never forget that google can be the best resource if ever get stuck.), but I'll try to explain nonetheless.

 

So, obviously, in programming, objects are not a material thing. We need to look at what an object is, in a more abstract/conceptual manner. Let's focus on this: An object is anything that can be seen or touched.

An Object can be seen.

If something can be seen, it would be safe to say it could be described as well, no? Well, in order to describe something, one usually lists off certain/unique characteristics or properties.

An Object can be touched.

If an object can be touched, that means something can be done with that object.

 

So, in programming, an object is simply a structure that has properties or attributes, and carries some kind of functionality-it can do things.

 

The object model and it's applications will make more sense as we progress; but I felt that since technically everything in Ruby is an object, and that I would be throwing the word around a lot, it would only be fair to give you some idea on at least what an object is.

 

So, when I say everything in ruby is an object, I mean everything in ruby is a data structure with attributes and methods (functions, it can do something). With that in mind, I'd like to go over some of ruby's core data types.

 

Integers

Integers are simply whole numbers:

-1
0
1
2
3
999

 

Floats

Floats are decimal point numbers:

-0.5
0.1
5.985

 

Strings

Strings are any kind and any number of characters:

"hello, world!"
"this is a string"
"&^$123"

 

Boolean

You can think of a boolean as a switch, with only 2 possible values: on or off. These values are represented by the ruby keywords:

true
false

 

Nil

Nil is a special data type, it is actually a representation of no value, or nothing. This value (or lack there of) is represented by the ruby keyword:

nil

if you have a background in another programming language, you probably have encountered the data type "null." In ruby, nil is conceptually the same as null.

 

I will touch on more as we progress, but this should be enough for now. I promise, in the next lesson we will actually write some code.

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...