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
class RPNCalculator | |
def initialize(expression) | |
@expression = expression | |
end | |
def evaluate(expression) | |
container = @expression.split(' ') | |
num_container = [] | |
container.each do |x| | |
if !(x == '+' || x == '-' || x == '*') |
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
# Don't forget to check on intialization for a card length | |
# of exactly 16 digits | |
class CreditCard | |
#Initialize CreditCard object | |
#make sure it return argument errror if not 16 digits | |
#thinking I need a regex that can take any string input and tell if it | |
#contains exactly 16 digits | |
def initialize(number) | |
unless number =~ /(\d{4})(\s*)(\d{4})(\s*)(\d{4})(\s*)(\d{4})/ |
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
# Method from Chris Pine for figuring out | |
# continent size in Civilization III | |
# with added return conditional for spots at the 'edge of the earth' | |
M = 'land' | |
o = 'water' | |
world = [[M,o,o,o,o,o,o,o,o,o,o], | |
[M,o,o,o,M,M,o,o,o,o,o], |
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
# Code from Codeacademy working on using class variables and class methods | |
class Computer | |
@@users = {} | |
def initialize(username, password) | |
@username = username | |
@password = password | |
@files = {} | |
@@users[username] = password |
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
class Account | |
attr_reader :name | |
attr_reader :balance | |
def initialize(name, balance = 100) | |
@name = name | |
@balance = balance | |
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
def separate_comma(number) | |
number.to_s.gsub(/(\d)(?=(\d{3})+$)/, '\1,') | |
end |
OlderNewer