Ruby on Rails

Ruby on Rails

Ruby on Rails is a dynamic open source, pure object-oriented programming language that focuses on simplicity and productivity.  Everything in Ruby is an object.  It also has a natural to read and easy to write elegant syntax.

I’m learning Ruby on Rails through an online course at UDEMY, taught by Mashrur Hossain and  Rob Percival.  I will be taking notes and posting my work here, so that I can remember them later.  It’s a fairly big course (48hrs), so I expect to be working on it on my off time for the next 2-3 months.  Examples and resources for Ruby on Rails can be found below.

Resources

Gems

  • bcrypt – An easy way to keep your users’ passwords secure

Quick Notes

String concat structure: 
String1 + ” ” + String2 + String3

Some methods that can be used on objects:
objectname.nil?
objectname.empty?
objectname.length
objectname.reverse

To escape the evaluation of #{variablename} within a String, prepend with \:
\#{variablename}

To get input from the command line and assign it to a variable
variablename = gets.chomp

Command Line Shortcuts

pwd (present working directory)
cd
(change directory)
(tab) (use tab to autotype and fill in names)
cd (tab) (shows any thing available in directory)
cd ~/(tab) (brings up all available directories, use tab again to autocomplete a directory name)
mkdir (make directory)
ls (to see files in a directory)
../ (back/up one directory)
clear (clears screen)
irb
(Interactive Ruby, it’s the run command to start a console)
exit (to exit the console)
ctrl-l (clear the screen, Note: does not work in Replit.com)
.class (suffix to find what class the object belongs to:. ex: string, integer, etc…)
.methods (suffix to pull up all the methods available to an object: )

Comparison Operators

Operator Name Example Result
== Equal x==y True if x is exactly equal to y.
!= Not equal x!=y True if x is exactly not equal to y.
> Greater than x>y True if x is greater than y.
< Less than x<y True if x is less than y.
>= Greater than or equal to x>=y True if x is greater than or equal to y.
<= Less than or equal to x<=y True if x is less than or equal to y.
<=> Combined comparison operator. x<=>y x <=> y : =
if x < y then return -1
if x =y then return 0
if x > y then return 1
if x and y are not comparable then return nil
=== Test equality x===y (10…20) === 9 return false.
.eql? True if two values are equal and of the same type x.eql? y 1 == 1.0 #=> true
1.eql? 1.0 #=> false
equal? True if two things are same object. obj1.equal?obj2 val = 10 => 10
val.equal?(10) => true