Skip to content

Instantly share code, notes, and snippets.

@gary1410
gary1410 / reverse_words
Last active December 20, 2015 09:58
Exercise: Reverse words Write a method reverse_words which takes a sentence as a string and reverse each word in it. I believe the logic is correct?
def reverse_words(str)
array = [ ]
array = str.split.each do |x|
end
str.reverse
end
@gary1410
gary1410 / gist:6091194
Last active December 20, 2015 07:09
Confused about while statements and line 6. I'm not sure I understand when to use a while state and "while true" means. Also, I'm confused about lines 6 and 7 concurrently. Why do you line 6 and then come back to say "if reply == 'yes.' Can anyone give an explanation here?
def ask(question)
while true
puts question
reply = gets.chomp.downcase
if (reply == 'yes' || reply == 'no')
if reply == 'yes'
answer = true
else
@gary1410
gary1410 / gist:6005238
Created July 16, 2013 02:10
Good guess exercise.
def good_guess?(int)
case int
when int == 42
return "true"
else
return "false"
end
end
@gary1410
gary1410 / gist:5930501
Last active December 19, 2015 09:09
Exercise: Calculate a letter grade
def get_grade(average)
case average
when 90..100
return 'A'
when 80..90
return 'B'
when 70..80
return 'C'
when 60..70
return 'D'
@gary1410
gary1410 / Defining a Method
Created June 30, 2013 02:08
Hey guys, I'm doing this exercise "Exercise: Define a method that returns a formatted address" and for the life of me I can't and figure out what I"m doing wrong Here were the direction. Create a method called make_address that accepts parameters for the street, city , state, and zip and returns a single address string. For example if we call th…
def make_address(street, city, state, zip)
return "You live at #{street} in the beautiful city of #{city}, #{state}. Your zip is #{zip}."
end
@gary1410
gary1410 / gist:5865129
Created June 26, 2013 06:19
Hi, this is my first gist.
asdfsadfasdfsadfasdfsdfasd