Friday, February 3, 2017

Post Two: The Basics


Given that Ruby is, in fact, a programming language, it can handle things like math, variables, conditionals, and loops.  In Ruby, math is very similar to other sorts of math.  You can see some ramblings of what works and doesn't work here:


And there you go.  It's pretty intuitive, although I did expect logs to be a little bit different.  If you want a particular base, you just do this:


And everything works out well in the end.  Variables are also easy, like so:


And conditionals are written like this: 


While for loops look like this:


Note that two dots make the variable go one step farther, while three produce the more traditional result.  The "#{}" thingy is pretty much string concatenation, where it will just put whatever i happens to be there.  Note also that the return value is the loop range, with the dots still preserved.

While loops are also quite simple:


Note that there's a "do" at the end of the while line, and that it returns a nil.

Here's an until loop, to show the slight difference:


And a wild Collatz Conjecture appears!  Note the lovely nested conditional and the return of nil.

Next time, I'll get the file system working so that irb(main): stops showing up and I'll be finally able to edit my mistakes!

Anyways, 'twas fun, and see you some time before the twelfth!

Jamie

Tuesday, January 31, 2017

Post One: It Begins

Given that I use a Mac, Ruby is included at shipping.  To access it, simply open Terminal and type "irb", without the quotes.

Ruby is an object-oriented, general-purpose language, which was made by Yukihiro Matsumoto in 1993.  Matsumoto was dissatisfied with the object-oriented languages of the day, which he either considered flawed, like Perl, or not true object-oriented languages, like Python.

I learned about Ruby some time ago, but I did not realize its utility until the Health IT conference/lecture/thing, where many of the professionals who spoke said they used Ruby.  After this, I went to Wikipedia and then Ruby-Lang.org, which told me everything I wanted to know.

Anyways, at first glance, Ruby seems quite like Python in structure.  The first Terminal shell reacts in much the same way, although there are some immediate differences such as the syntax and the fact that the values are also returned -- and things like "puts()" (the same as "print()" in Python and "System.out.println()" in Java) return not only the printed line but also a "=> nil".

And as such, here's the famous "Hello World" in Ruby form:
The first command does not print "Hello World", but merely returns the value.  The purpose was to demonstrate what a return looks like.  The second command prints "Hello World" -- notice the lack of quotation marks and the return of nil.

So onward into the mystical world of Ruby, where I shall be uploading both on a rigid schedule and whenever the mood strikes me!

See you sometime before the fifth,

Jamie