Skip to content

Instantly share code, notes, and snippets.

@adriculous
Last active July 21, 2016 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adriculous/89c46f295982de91481f9452fdfe4f89 to your computer and use it in GitHub Desktop.
Save adriculous/89c46f295982de91481f9452fdfe4f89 to your computer and use it in GitHub Desktop.
"Always Three" Refactoring Challenge #1
# You are now at the Always 3 script. It's in Ruby, girl. Hello and welcome!
# Ask the person (user) to provide a number. Any number.
puts "Please, give me your number, I mean A number!"
# Hint: use 'gets' method, convert to an integer using 'to_i', make it a variable
i_number = gets.to_i
# (Refactoring script) Need to refactor using only two variables. I took out the ii_number variable from the old version and left with i_number and fin_number. Maybe...
fin_number = i_number
# add 5
fin_number+=5
# multiply by 2
fin_number*=2
# subtract 4
fin_number-=4
# divide by 2
fin_number/= 2
# subtract i_number from fin_number
fin_number-=i_number
# show fin_number back to person/user
puts "You know what it is! #{fin_number}, of course!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment