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
2.2.0 :001 > def sayhi | |
2.2.0 :002?> puts "HI!" | |
2.2.0 :003?> end | |
=> :sayhi | |
2.2.0 :004 > def greeting(name) | |
2.2.0 :005?> puts "Hi, #{name}." | |
2.2.0 :006?> end | |
=> :greeting | |
2.2.0 :007 > greeting("Bill") | |
Hi, Bill. |
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
# must be baller and either furnished or rent cheaper than 2100 | |
def rent?(furnished, rent, baller) | |
puts "Furnished is #{furnished}, rent is #{rent}, baller status is #{baller}" | |
if baller && (furnished || rent < 2100) | |
puts "Yeah, let's do it. \n" | |
return true | |
else | |
puts "Nah, I don't want it. \n" | |
return false | |
end |
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
# Sort the array from lowest to highest | |
def sort(arr) | |
a_length = arr.length | |
return arr if a_length == 1 | |
return [] if a_length == 0 | |
keep_going = true | |
while keep_going do | |
flagged = false | |
arr.each_with_index do |num,index| | |
unless (index + 1 == arr.length ) # Can't compare last number with next one since it doesn't exist. |
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
def calculate(size,num_colours) | |
colour_price = 10 | |
colour_price = 15 if num_colours > 2 | |
total = ((size * 15) + (num_colours * colour_price)) * 1.15 | |
total_in_currency = "%05.2f" % total | |
puts "Your total is $#{total_in_currency}" | |
end | |
# Enter size of sign, and number of colours as parameters | |
calculate(10,3) |
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
require 'pp' | |
def count_letters(stuff) | |
result = {} | |
individual_characters = [] | |
individual_characters = stuff.split("") | |
individual_characters.each do |char| | |
next if char == " " | |
if result[char].nil? | |
result[char] = 1 |
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
@states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan' | |
} | |
@states[:OH] = 'Ohio' | |
@states[:NC] = 'North Carolina' |
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
@states = { | |
OR: 'Oregon', | |
FL: 'Florida', | |
CA: 'California', | |
NY: 'New York', | |
MI: 'Michigan' | |
} | |
@states[:OH] = 'Ohio' | |
@states[:NC] = 'North Carolina' |
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
require 'pp' | |
# BUYING | |
# num_bottles = money/2 | |
# REDEEMING | |
# num_bottles = caps * 0.25 | |
# num_bottles = bottles * 0.5 | |
def buy(investment=0) |
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
require 'pp' | |
# I = 1 | |
# V = 5 | |
# X = 10 | |
# L = 50 | |
# C = 100 | |
# D = 500 | |
# M = 1000 |
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
def benchmark | |
start = Time.now | |
yield | |
running_time = Time.now - start | |
end | |
# Be careful, pasting this into IRB will take a long time to print. | |
# It's a loooong string. :) | |
long_string = "apple"*100000000 | |
OlderNewer