Shannon Fang wrote:
> I only know ansi C. I can't say I know ansi C++, because it is way out
> of control. To implement your code I will write,
> 
> action="sleep"
> if action=="sleep" then ... end

A string comparition is both overkill for this kind of thing and posed
for the dangers inherent in _mutable_ strings. 

> Still very very confused, is symobol closer to a variable or closer to
> the value of the variable? I don't know why :sleep.to_s is "sleep". What
> is the relationship between symbol and string??

As I understand it, a Symbol is just an internalized, immutable String.
Internalized as in stored in a big central place controlled by Ruby
itself. Immutable as in can't be modified, never ever.

Imagine a big index of words which are the symbols. They are entered,
but never erased, from that big book of symbols. Since they are
internalized, you have less storage overhead. Each symbol merely
translates to a lookup in the big book, whereas both your 'action' and
'"sleep"' string would take up 4 spaces: the two String objects and each
of their underlying char* structures. 

Symbols aren't really closer to neither the variable nor the value of
the variable. A variable has a name. A method has a name. A class has a
name. And when you want to refer to the name itself (and not what the
name refers to), you can either waste resources with some Strings, or
use the unique Symbol for that name.

> class HTTP
>     def HTTP.get1
>     end
>     def HTTP#get2
>     end
>     def get3
>     end
> end
> 
> Then, get1 is class method, 

Correct.

> get2 is instance method.

No, it's a parse error. However, it is a common way of _denoting_ an
instance method, first seen in the PragProg ProgRuby book, AFAIK.

> How about get3???

Now that is an instance method. But in plain text, we'd rather write
HTTP#get3 for brevity, since HTTP.get would be misleading and "get3 of
class HTTP" would bore the daylights out of us.

-- 
(\[ Kent Dahl ]/)_    _~_    __[ http://www.stud.ntnu.no/~kentda/ ]___/~
 ))\_student_/((  \__d L b__/  NTNU - graduate engineering - 5. year  )
( \__\_/__/ ) _)Industrial economics and technological management(
 \____/_\____/ (____engineering.discipline_=_Computer::Technology___)