Skip to content

Instantly share code, notes, and snippets.

Greg MtnBiker

Block or report user

Report or block MtnBiker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:9845183
class GameBoard
def initialize
puts "Now the game starts"
end
def set_locations_cells(locations)
@locations = locations
@all_three = [] # storing guesses
end
View gist:9224528
# 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']}"
View w2e2.rb
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|
@MtnBiker
MtnBiker / gist:9063879
Last active Aug 29, 2015
Leap year w2e3 Ruby Course.
View gist:9063879
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
View gist:8968769
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
You can’t perform that action at this time.