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 GameBoard | |
def initialize | |
puts "Now the game starts" | |
end | |
def set_locations_cells(locations) | |
@locations = locations | |
@all_three = [] # storing guesses | |
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
# Exercise3. Make use of the class Dir for the following - | |
# | |
# Display your current working directory. | |
# Create a new directory tmp under your working directory. | |
# Change your working directory to tmp | |
# Display your current working directory. | |
# Go back to your original directory. | |
# Delete the tmp directory. | |
puts "1. #{ENV['PWD']}" |
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
textfile = 'w2e2.textFile.txt' | |
word_to_change = "word" | |
new_word = "inserted word" | |
lineArr = [] | |
newTextContents = "" | |
File.open(textfile, 'r') do |f1| | |
while line = f1.gets | |
lineArr = line.split(" ") | |
# should be done with RegEx, but since we haven't done that yet | |
lineArr.each { |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
def not_leap_year(year) | |
puts "#{year} is not a leap year" | |
end | |
def leap_year(year) | |
if (year % 4) == 0 | |
if year % 100 == 0 | |
if year % 400 == 0 | |
puts "There are #{year*366*24*3600} seconds in the leap year #{year}" | |
else |
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_age (age_in_seconds) | |
seconds_in_year = 365*24*3600 | |
seconds_in_month = seconds_in_year/12 | |
years = age_in_seconds/seconds_in_year # this gets truncated which is fine | |
months = (age_in_seconds - (years * seconds_in_year))/seconds_in_month | |
puts "I’m #{years} years and #{months} months old." | |
[years, months] # following your suggestion to return an array | |
end | |
ageArr1 = calculate_age 979000000 |