So I’ve been up reading all night, my eyes are aching… I’ve got Hello
World! down pretty good, and I can make it repeat a few times… lol No
biggie there though, I’ve done that in C++ before. However Ruby makes me
feel like I can actually do this programming stuff… If I just knew what
the different functions did.
I’ve got an idea for a ¿script? I want written, but I’m not quite sure
how to get it done. I can’t seem to find a solid list of all the
¿functions? I’ll need to be using, so I just keep guessing. I’ve even
tried if/then statements hehe.
There’s two parts to what I need this ¿script? to do… Second part
doesn’t matter if the first part doesn’t get on track, so let’s deal w/
it first. What I need is… A 2-6 letter word generating program that
will save the words produced to a text file, neatly separated by
something like a comma or colon, something Ruby will be able to read at
a later date w/o separation issues.
I want to start out with double A’s and end up with 6x Z’s, or as close
to that but with full words…
On a side note, I found a script on another site someone else was
working on towards a similar end… However it wasn’t completed to the
specifications that the person wanted, nor I want, and I can’t even get
the thing to run. That may be because I found it on a mac site and I’m
running windows, idk… I forgot to check n see what OS the OP of that
thread was running, maybe someone here can shed some light on this. Tell
me if it’s a mac script, if not what’s going wrong, if so can it be
edited to work for windows? Any help would be greatly appreciated, even
if it’s just telling me what some of the functions mean/do and if
they’re windows/mac functions.
I’m sure anyone who reads this is wondering what I want this sorda
program for, so I’ll tell you… It’s for a game, I want it to select
names on a very old game. 99.95% of the names on this game are taken,
and I’m hoping to get lucky and snag a couple decent ones with this
program if I can get it running. It’s an online game ofc, and the cooler
the name you have the cooler you look ^.^ Just wanted ya to know I
wasn’t tryna make a brute force or any kinda cheat lol
well, finding a complete list of all the methods (not usually called
functions in ruby) you’ll need/want to use is a pretty tall order…
there are ruby kernel methods
(Module: Kernel (Ruby 1.9.3)) that you can call
pretty much anywhere - things like puts, require, etc. etc.
since you’ll be working with words, take a look at the String class
and it’s methods (Class: String (Ruby 1.9.3)) - one
way to create a String like this…
some_string = “This is a String!”
…now play around with all the different methods to get a feel for
how they work and what they do.
some very handy methods that most every ruby object shares (and a
String, like just about everything else in ruby is an object,) are #methods, and #instance_methods.
to see all the methods that can be called on an instance of String,
you could do this:
String.instance_methods.sort.each{|m| puts m}
or
string = “This is a String!”
string.methods.sort.each{|m| puts m}
both #methods and #instance_methods return an Array
(Class: Array (Ruby 1.9.3)) which has the #sort, and #each methods. neat, right?
the docs are good, check out the basic classes and their methods and
play around with them some.
seems like loops and iterators will be an important part of your
project as well - there’s a good tutorial here:
If you installed the reference implementation at
“http://www.ruby-lang.org”, you will find a Documentation folder in the
Start:Ruby193-pxxx folder in your Windows Start menu. This will include
a help file that documents the API of the core and standard libraries,
which includes all of the basic methods and classes), and a PDF called
“The Book of Ruby”, which is a Guide to learning the language and the
most-used core APIs.
The bad news is that all Ruby documentation is crap. Rife with:
Tutorials that only allow you to recreate the examples without any
knowledge of how to expand on them.
Erroneous and deprecated information.
Incomplete information and bad presumptions by the author as to how
everyone ought to program.
And, worst of all, a complete disregard for how each element is
INTENDED to be used. They simply tell you the name, input, and output
with no clue as to why it exists or was implemented in that fashion to
begin with.
In other words, the same as for any other language.
The good news is: Your project is exactly the type of algorithm Ruby was
designed to implement.
Look up the String class in the API helpfile and scroll down to the
succ() or next() methods (Truly awful names). That method will increment
the value of your string a-z from the last character to the first,
preserving case. So ‘zz’.next returns ‘aaa’.
Using the record separator variable “$=‘:’” with the print() and
gets() methods will easily write and read words separated by the ‘:’
delimiter.
That should get you rolling downhill into freeway traffic in no time.
Enjoy!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.