![]() |
|
daffy duckifier in ruby - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: daffy duckifier in ruby (/Thread-daffy-duckifier-in-ruby) |
daffy duckifier in ruby - Inori - 08-26-2014 I made this in a lesson on code academy. Personally, I think it's hilarious. It doesn't do much but it turns any "s" in the initial string to a "th" turning it in to a lisp- er, lithp. Code: puts "Daffy Duckifier by RR"
print "feed me strings!"
string = gets.chomp
string.downcase!
if string.include? "s"
string.gsub!(/s/, "th")
else
print "nothing to duckify :("
end
puts "#{string}"RE: daffy duckifier in ruby - Singularity_mybb_import13102 - 08-27-2014 Man, I love Ruby. I actually remember being where you are now about a year ago. I recall making that same program as well ![]() Here is some code from about six months ago I wrote (Rock Paper Scissors) Code: #!/usr/bin/ruby
WINS = { :computer => 0, :user => 0, :draws => 0 }
HANDLER = {
:rock => { :rock => :tie, :paper => :lose, :scissors => :win},
:paper => { :rock => :win, :paper => :tie, :scissors => :lose},
:scissors => { :rock => :lose, :paper => :win, :scissors => :tie },
}
def computer
choice = rand(1..3)
choice == 1 ? :rock : choice == 2 ? :paper : :scissors
end
def compare(outcome)
if outcome == :win
puts "You win!"
WINS[:user] += 1
elsif outcome == :lose
puts "You lost!"
WINS[:computer] += 1
else
WINS[:draws] += 1
puts "Tie game!"
end
end
def play
puts '
|---------------------------------|
| ROCK PAPER SCISSORS! |
|---------------------------------|
'
puts "Enter choice: Rock (1), Paper (2), or Scissors (3)"
comp_choice = computer
case gets.chomp.to_s.downcase
when 'rock', '1'
puts "You chose : Rock"
puts "Computer chose: #{comp_choice.capitalize}"
compare(HANDLER[:rock][comp_choice])
when 'paper', '2'
puts "You chose : Paper"
puts "Computer chose: #{comp_choice.capitalize}"
compare(HANDLER[:paper][comp_choice])
when 'scissors', '3'
puts "You chose : Scissors"
puts "Computer chose: #{comp_choice.capitalize}"
compare(HANDLER[:scissors][comp_choice])
else
puts "Invalid choice!"
end
puts "Would you like to play again? [Y/n]"
cont = gets.chomp.downcase
system "clear" or system "cls" # Clear the screen regardless of os
if cont == "y"
play
else
puts "Your total score: #{WINS[:user]} | Computer total score: #{WINS[:computer]} | Total draws: #{WINS[:draws]}"
puts "Thank you for playing!"
end
end
playCodecademy will teach you the basics like syntax, but to really grasp Ruby, you have to do a lot of your own personal projects. RE: daffy duckifier in ruby - Psycho_Coder - 08-27-2014 Added Source Tag |