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
# Determine whether a string contains a Social Security number. | |
def has_ssn?(string) | |
#check overall length | |
if string.length < 11 | |
return false | |
#check for match | |
elsif string.match(/\d{3}(-)\d{2}(-)\d{4}/) | |
return true | |
else | |
return false |
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 reverse_words(str) | |
array = [] | |
result = "" | |
str.each_line(" ") { |s| array.push(s.reverse)} | |
array.each do |i| | |
result = result + i +" " | |
end | |
result = result.chop.lstrip | |
puts result | |
return result |
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 evaluate(input) | |
puts "BEGIN NEW CALC" | |
stack = [] | |
puts "Initial input is #{input}" | |
until input == "" | |
item = input.match(/\A\S*/) | |
puts "Current item is #{item}" | |
item_string = item.to_s |
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 Array | |
def pad!(min_size, value = nil) | |
array = self | |
diff = min_size - self.length | |
if diff <= 0 | |
return self | |
else | |
diff.times do | |
array.push(value) |
NewerOlder