Min slöa start i ruby

OK detta är ett av mina första stapplande steg i Ruby, inte direkt vackert.
[sourcecode language=”ruby”]
require "mysql"

def mydbconnect
mydb = Mysql.real_connect("localhost", "johndo", "mittprivatapassword", "johndo")
end

def show_active
sh_active = mydbconnect.query("SELECT id, text, done FROM todo WHERE done=’0’")
printf("Currently active things\n")
while row = sh_active.fetch_row do
printf("%s. %s\n", row[0], row[1])
end
end

def show_issue(iss)
sh_active = mydbconnect.query("SELECT id, text, done FROM todo WHERE id=#{iss}")
puts ""
while row = sh_active.fetch_row do
printf("\nID: %s", row[0])
puts
printf("\nText: %s", row[1])
puts
end
end

def show_inactive
sh_done = mydbconnect.query("SELECT id, text, done FROM todo WHERE done=’1’")
printf("Stuff done\n")
while row = sh_done.fetch_row do
printf("%s. %s\n", row[0], row[1])
end
end

if __FILE__ == $0
show_active
end
[/sourcecode]

,

Powered by WordPress. Designed by WooThemes