As others have said, you're going to want to start small. Too many try and make some type of battle system or other monster as their first ever script. Unless you're already a substantially established programmer, that's a bad idea.
If I were you, and you really want to be proficient in Ruby as a language instead of just a patch hacker, listen along.
Your first step is to acquire this book:
http://www.amazon.com/Practical-Object-Oriented-Design-Ruby-Addison-Wesley/dp/0321721330
Read through that. That'll get you a good practical introduction to OO programming in Ruby and how to properly separate things.
Look into programming problem sites like project euler, rosalind, code katas, and code wars.
If you're really looking for problems, look into ones from Google interviews.
In fact, here's a hard one to start with: (Note that using OO in this one is a bad idea [see java implementations], functional programming however...)
# Given a wordlist:
http://www-personal.umich.edu/~jlawler/wordlist# and a word: dog# # Find all anagrams of the word, such that the result is: [dog, god]# Gives you an array of all wordswordlist = Net::HTTP.get(URI('http://www-personal.umich.edu/~jlawler/wordlist')).splitThe answer: (try to solve it first or it's no fun, and yes this is a harder problem)
Spoiler
Code:
# Simple functional style# =======================my_word1 = 'dog'Net::HTTP.get(URI('http://www-personal.umich.edu/~jlawler/wordlist')).split.select { |word| word.length == my_word1.length && word.chars.sort == my_word1.chars.sort}# Functional style with closures# ==============================word_finder = -> { # Notice that no matter how many times you call this, wordlist is still there. # That's because the returned function below encapsulates the state around it when it's # defined, and this includes the wordlist. wordlist = Net::HTTP.get(URI('http://www-personal.umich.edu/~jlawler/wordlist')).split # Now we just return the function here which takes my_word and returns the array we want -> my_word2 { wordlist.select { |word| word.length == my_word2.length && word.chars.sort == my_word2.chars.sort } }}.call # We call the first function to close over the value wordlist, and it returns a function that# we've named word finder# There are three ways to call this:# word_finder.call('dog')# word_finder.('dog')# word_finder['dog']# OO style# ========class Dictionary def initialize @wordlist = Net::HTTP.get(URI('http://www-personal.umich.edu/~jlawler/wordlist')).split end def anagrams(word) # Fun fact, select is actually functional, and blocks are anonymous functions, so this is really a hybrid @wordlist.select { |word| word.length == my_word.length && word.chars.sort == my_word.chars.sort } endend# Dictionary.new.anagrams 'dog'# OO with Caching# ===============class Dictionary2 def initialize @wordlist = Net::HTTP.get(URI('http://www-personal.umich.edu/~jlawler/wordlist')).split @cache = {} end def anagrams(word) # If our cache already has it, return that value instead return @cache[word] if @cache[word] @wordlist.select { |word| word.length == my_word.length && word.chars.sort == my_word.chars.sort }.tap { |words| # In this case we tap into the value returned before it goes out # Iterate over each of the words, and store keys for each word for the above # cache call to prevent duplicate searches. This is far faster words.each { |word| @cache[word] ||= words } } endend# Dictionary2.new.anagrams 'dog'
Do note that it'll take you a good amount of time to be able to swing something like that, as that actually is a Google interview question. Having said that, don't look at the code until you give it a few shots. It can be a benchmark on how much you know already.