~3m skim, 492 words, updated Nov 20, 2020
A beautifully expressive hacker language. Mostly used for rails.
Programming is tough. Especially at first.
Whatever you are learning or writing, keep in mind that every language was created with a set of principles and use cases in mind - some more than others.
Learn to reject your ego. Learn to love burning code.
Name things what they are. Begin with your program’s final state in mind!
puts "Hello, Ruby!"
In descriptors: high-level, object-oriented and interpreted. Ruby occupies a similar market space to Python, with both striving to create a more human-readable language. I’ll update this as I learn more, with my primary resources being
Ruby Koans
and
Codecademy
. In code blocks below, #>
indicates text that is printed to the console.
I’m not, really; it seems like a fun language with lots of respected devs. I don’t have time to learn or tinker with this very flexible scripting lang at the moment. At one point in early 2019, I spent a short, intense period binge-learning C++, then Ruby, in order to meet requirements and complete technical interviews at C++/Ruby shops.
Running ruby -v
will print your ruby version. If you have a ‘good’ OS, you should have a version built in. Upgrade if the version is less than 2. ruby
runs ruby programs. irb
starts an interactive ruby prompt.
On Debian, it is best to add /.gem/ruby/2.3.0/bin
to your PATH in ~/.profile
, and gem: --user-install
to your ~/.gemrc
. Be careful not to run gem, bundle, etc as root.
Adding this user bin to your PATH makes it easy to use tools like
RuboCop
(gem install rubocop
) to rubocop --fix-layout *.rb
your ruby files.
Resources:
number = 18
boolean = true
string = "Hello"
puts "String" #Appends a newline
print "String"
puts
and print
are used for output, the only difference being that puts
appends a newline after printing the given string.
x = (3 + 3) / 2 #Brackets
x = 3 ** 2 #Exponents
x = 3 / 3 #Division
x = 3 * 3 #Multiplication
x = 3 + 3 #Addition
x = 3 - 3 #Subtraction
x = 3 % 3 #Modulo
The only operation that may be foreign is modulo, which is the remainder of a division. For instance, running 128 / 13
will give 9, and 128 % 13
will give 11. Stepping backwards, 13 * 9
is 117, and adding 11 gives 128.
x = "String length".length
puts x #> 13
Methods without arguments (or to be invoked with only default arguments,) can be called without brackets ( )
.
puts "RoFlMaO".upcase.reverse.downcase
#> oamlfor
Reverse
x = "Ruby is interesting...".reverse
puts x #> ...gnitseretni si ybuR
Upcase/Downcase
puts "Ruby is interesting...".upcase
#> RUBY IS INTERESTING...
puts "Ruby is interesting...".downcase
#> ruby is interesting...
Comments can be included anywhere, and are formatted as follows:
# Single line.
=begin
Multi-line.
=end
Names are all lowercase and words are separated with _
.
large_number = 7893425089273045
player_name = "Jimothy"
Intro
puts("Hello, World!")
Intro
Intro
puts("Hello, World!")
After installing MongoDB and loading http://media.mongodb.org/zips.json into the database, (or another from https://github.com/ozlerhakan/mongodb-json-files ,)
Pages are organized by last modified.
Title: Ruby
Word Count: 492 words
Reading Time: 3 minutes
Permalink:
→
https://manuals.ryanfleck.ca/rb/