-
- Install Ruby from: https://rubyinstaller.org/downloads/
- You should install 'Ruby+Devkit 2.4.4-2' and either the 32 or 64 bit version dependent on your OS.
-
- After installing, open up Powershell (with elevated permissions by running it as Admin) and send the command
ruby -v
. You should get a ruby version back. If you do not, try restarting your computer.
- If everything is installed correctly, you should be able to send the 'irb' command to open up the ruby shell and play around with some basic code. You can do
3+4
or"string".gsub('i', 'o')
or something.
- After installing, open up Powershell (with elevated permissions by running it as Admin) and send the command
-
- You save Ruby files with the extension '.rb'. You run Ruby files by calling
ruby /path/to/file.rb
.
- The easiest way to check this is to put something like
p "Hello World!"
in a .rb file and simply trying to run it.
- You save Ruby files with the extension '.rb'. You run Ruby files by calling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source ~/.bashrc | |
# echo is like puts for bash (bash is the program running in your terminal) | |
echo "Loading ~/.bash_profile a shell script that runs in every new terminal you open" | |
# $VARIABLE will render before the rest of the command is executed | |
echo "Logged in as $USER at $(hostname)" | |
# Load RVM into a shell session *as a function* | |
# Path for RVM |
You are walking down the street, thinking about how to best model reality through code in order to create the ultimate Pet Diet app, and you stumble across a conundrum. You have a model of a cat and a model of a dog. They are both animals and share similar properties with one another, but in order to model them in code, you'd have to re-write attributes like weight, age, dietRestrictions, and owner. While you could sit down and write out a new object for every pet type that comes your way, but there has to be a better way to share attributes and functionality between similar objects.
Both the dog and cat should be able to run, jump, play, hunt, eat and reproduce. But, can't most mammals do something similar? They have more baseline similarities than differences, and for the purposes of your app, they really only end up being different species with may more in common than they have differences.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let's build a model that inherits from Animal. | |
var Animal = function(){ | |
this.environment = 'none' | |
this.species = 'none' | |
this.name = 'none' | |
this.hunger = 5 | |
this.consume = function(food){ | |
if(food){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////// | |
// Constructors // | |
////////////////////// | |
// This is a constructor. When you call 'new Person', it evokes this function and returns an object with whatever properties got assigned to 'this'. | |
var Person = function(name, age, weight){ | |
this.name = name | |
this.age = age | |
this.weight = weight | |
this.location = "Earth" |
NewerOlder