Login Register


daffy duckifier in ruby filter_list
Author
Message
daffy duckifier in ruby #1
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}"
just save as "whatever.rb"
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

Reply

RE: daffy duckifier in ruby #2
Man, I love Ruby. I actually remember being where you are now about a year ago. I recall making that same program as well Biggrin

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 play

Codecademy will teach you the basics like syntax, but to really grasp Ruby, you have to do a lot of your own personal projects.
[Image: obDhRdK.gif]

Reply

RE: daffy duckifier in ruby #3
Added Source Tag
[Image: OilyCostlyEwe.gif]

Reply







Users browsing this thread: