most useful instance methods

A

Adam Akhtar

Ive just been getting to grips with some of the string and array
methods. The basics were easy enough such as reverse. Then came map and
uniq. Im wondering what else is good to practice with. It seems to make
sense to study new methods on the basis of their useage. So what methods
do you constantly use or couldnt live without for arrays and strings
without including the elementary stuff like push pop etc.

Perhaps you think there arent that many methods but to a beginner like
me every time i open the pickaxe to look at what method could help solve
a problem I soon feel lost amongst them.
 
T

Trans

Ive just been getting to grips with some of the string and array
methods. The basics were easy enough such as reverse. Then came map and
uniq. Im wondering what else is good to practice with. It seems to make
sense to study new methods on the basis of their useage. So what methods
do you constantly use or couldnt live without for arrays and strings
without including the elementary stuff like push pop etc.

Perhaps you think there arent that many methods but to a beginner like
me every time i open the pickaxe to look at what method could help solve
a problem I soon feel lost amongst them.

I suggest reading though the whole reference section, at least enough
to get a quick imprint of every core method. Start with Kernel/Object
though.

T.
 
T

Thomas Wieczorek

Ive just been getting to grips with some of the string and array
methods. The basics were easy enough such as reverse. Then came map and
uniq. Im wondering what else is good to practice with. It seems to make
sense to study new methods on the basis of their useage. So what methods
do you constantly use or couldnt live without for arrays and strings
without including the elementary stuff like push pop etc.

inject, *, +, -, sort(with and without block), compact and join from the Array.
 
J

James Britt

Trans said:
I suggest reading though the whole reference section, at least enough
to get a quick imprint of every core method. Start with Kernel/Object
though.

Good plan.


The problem with trying to pick the "most used" is that it becomes
self-fulfilling. Most people will tend to use the methods that are most
familiar, which makes them *more* familiar, which makes them more often
used. And so on.

Here's a small hacking project:

Write a ruby app that grabs a random API page from ruby-doc.org and
brings it up in a browser.

Run it a few times each day and scan over what you see.

After a while, as you code, you'll start recalling various methods that
seem just right for various tasks, and your Ruby vocabulary and
experience will expand.
 
T

Thomas Wieczorek

Write a ruby app that grabs a random API page from ruby-doc.org and
brings it up in a browser.

What a great idea! I just wrote it. Thank you!

For those interested: It uses the Windows start command to open a site
from the Ruby 1.8.6 Core rubydoc list.

require 'open-uri'
require 'hpricot'

base = "http://ruby-doc.org/core/"
topic_site = Hpricot(open(base + "fr_class_index.html"))
list = topic_site.search("//div[@id='index-entries']/a[@href]")
system("start " + base + list[rand(list.length)].attributes['href'])
 
A

Adam Akhtar

yeah sounds like a cool learning project as well. Ive deliberately
avoided looking at the above code and will give this a shot. Thanks as
well for the method recs!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top