Skip to content

Instantly share code, notes, and snippets.

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
@MtnBiker
MtnBiker / gist:9063879
Last active August 29, 2015 13:56
Leap year w2e3 Ruby Course.
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
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|
# 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']}"
class GameBoard
def initialize
puts "Now the game starts"
end
def set_locations_cells(locations)
@locations = locations
@all_three = [] # storing guesses
end