Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Let's practice some basic Ruby to make sure that everything you've learned so far sticks. We'll review how to define a method that accepts some parameters and returns a value, and then how to call that method.
Ruby math operators
These are covered in more detail in the Math Operations and Operator Precedence videos in the Ruby Basics course, but here's enough to get you by for now:
Add two numbers:
2 + 1
Subtract two numbers:
2 - 1
Multiply two numbers:
2 * 2
You can also do math operations on numeric values stored in variables:
length = 2
width = 4
puts length * width
You can ensure one operation takes place before any others by surrounding it with parentheses:
# Add length and width, THEN double the result
(length + width) * 2
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up