Last active
August 29, 2015 14:07
-
-
Save lisakstep/c0a6d92642ba5fa9778c to your computer and use it in GitHub Desktop.
This file contains 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
# Strings | |
"hello 1 world" | |
p "hello 2 world" | |
p 'hello 3 world' | |
p 4 | |
# Booleans, variables and symbols | |
p true | |
p false | |
my_string_variable = "hello world" | |
p my_string_variable | |
my_boolean = true | |
p my_boolean | |
a, b = 1, 2 | |
p :hello | |
p :hi123 | |
p :HELLO | |
# Math Operations | |
p 1 + 2 | |
p 5 - 1 | |
p 6/2 | |
p 4*3 | |
p 2 ** 3 | |
p "using variables for math" | |
x = 10 | |
p x | |
x = x + 5 | |
p x | |
x += 5 | |
p x | |
p "less than and greater than" | |
p 4 > 5 | |
p 3 < 6 | |
p 5> 5 | |
p 4 == 5 | |
p 3 == 3 | |
p "greater than or equal" | |
p 4 >= 4 | |
p 5 >= 999 | |
p "order of operations" | |
p ( 3+4) *7 | |
p 3 + 4 * 7 | |
sum = 3 + 4 | |
p sum * 7 | |
p "variables and comparisons" | |
wins = 11 | |
losses = 5 | |
p wins > losses | |
p wins == losses | |
p "strings and operations" | |
hello ="hello" | |
p hello * 3 | |
p hello + " world" | |
p "string interpolation" | |
p "hello #{3}" | |
num = 5 | |
p "hello #{num}" | |
p "3 + 4 = #{3+4}" | |
num1 = 3 | |
num2 = 4 | |
p "3 + 4 = #{num1 + num2}" | |
p "Here is a symbol: #{:easy}" | |
p "#{num1} + #{num2} = #{num1 + num2}" | |
# Compound Interest calculation | |
principal = 10_000 | |
rate = 0.05 | |
time = 5 | |
num = 12 | |
amount = principal * (1+ rate/num) ** (num*time) | |
p "After #{time} years I'll have #{amount} dollars" | |
# Nil | |
p "Bloc"[7] | |
p "Bloc"[2] | |
nilly = nil | |
p nilly | |
# Methods | |
def hello | |
"Hello world" | |
end | |
p hello | |
def return_three | |
a = 1 | |
b = 2 | |
a + b | |
end | |
p return_three | |
# num = number of times compounded | |
def compound_interest(name, principal, rate, years, num) | |
amount = principal * (1 + rate/num) ** (num * years) | |
"After #{years} years, #{name} will have #{amount} dollars!" | |
end | |
p compound_interest("Bob", 100, 0.05, 40, 12) | |
p compound_interest("Joelle", 250, 0.06, 50, 12) | |
# my link method | |
def link(site_address, site_name) | |
"<a href='#{site_address}'>#{site_name}</a>" | |
end | |
p link("www.mysite.com", "My Site!") | |
# implicit and explicit parens | |
p "Hey there" | |
p("Hey there") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment