Phase three of FlatIron introduced us to Ruby and SQL, but was more concentrated on Ruby. Ruby is an Objected Oriented programing language, to which we were told “Everything is an Object.” Because that sentence doesn’t hold any greater meaning to me, I decided to investigate a little further to try and make sense of that cryptic aphorism.
Object-Oriented Programing
According to infallible Wikipedia on object-oriented programing languages, “Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).” It goes on to mention that methods can be attached to objects to modify the data (In ruby I have really been enjoying the simplicity of “dot chaining” those methods to anything I want).
Also written on that Wikipedia “In this brand of OOP, there is usually a special name such as this or self to refer to the current object.” This has been especially useful in creating our custom methods, for a specific instance or an entire class.
One of the major aspects of OOP seems to be this idea of classes which according to Wikipedia is “the definitions for the data format and available procedures for a given type or class of object; may also contain data and procedures (known as class methods) themselves, i.e. classes contain the data members and member functions” and the relationship to objects which are “instances of classes”. I am not sure why but it makes me think of this Russian (Matryoshka- I looked it up) doll, with each larger one being a class to the smaller one and each smaller one being object or instance of its larger class.
Ruby
I'd like to start off by saying I really do appreciate Yukihiro Matsumoto. This quote makes me think he is a good guy.
“Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run fast. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves.”
Forget John Connor I think we know who our real champion is. For me, early on, you could tell by the naming convention of certain methods that this language was created to be, dare I say intuitive. Iterating through arrays and hashes seems much simpler than JavaScript. Even the following bit of code leaves little to guess what is going to happen:
100.times do
Customer.create(
name: Faker::Company.name,
address: Faker::Address.street_address
)
end
I'm sure this will change as things get more complex but for now, I am very content with the “dot-chaining” and method naming conventions.
Ruby Gems
Just like the libraries and frameworks (ex: Bootstrap) with React in phase 2, ruby has a package manager called Gems. All of these Gems can be found at https://rubygems.org/ . Each gem has a name (ex. Rake), version (13.0.6), and platform (ex. Ruby – which means it works on any platform Ruby runs on.). Platforms depend on CPU architecture and operating system (MAC OS, Windows OS, etc). According to this following link each Gem follows the following file structure:
To find out more about the GEM you would read the README file to get the proper procedure for installation and usage. The gemspec contains specific information about the author and version. The lib file contains the code, and the executable file is in the bin. A gem usually has a rake file, Rake is also a gem that was mentioned above. The gem’s rake file will allow you to automate tests, generate code and perform other actions from the CLI of your computer.
I did really enjoy this security aspect of ruby gems in the FAQ link
“The same way you can trust any other code you install from the net: ultimately, you can’t. You are responsible for knowing the source of the gems that you are using. In a setting where security is critical, you should only use known-good gems, and possibly perform your own security audit on the gem code.
The Ruby community is discussing ways to make gem code more secure in the future, using some public-key infrastructure. To see the progress of this discussion, visit the rubygems-trust organization on GitHub”
Overall the message seems to be that ruby gems are a powerful tool just be careful what you download
Top comments (0)