Todd Benson wrote:
> On 7/24/07, Ralph Grothe <ralph.grothe / itdz-berlin.de> wrote:
>> Hello,
> 
> It should.  Did you compile with readline (you need to have
> lib-readline of course).
> 

Hi Todd,

please see my response to Stefano's reply.


> Yes, but as in all easy things, there are caveats.
> 
> You can 'open' up any class, and, in fact, any object whenever you want.
> 

This "opening" sounded rather unfamiliar to me.

> irb> a = "hello"
> => "hello"
> irb> b = "hajimemashite"
> => "hajimemashite"
> irb> a.class
> => String
> irb> b.class
> => String
> irb> class String; def welcome_f; puts self + ", welcome to f method!"; 
> end; end
> => nil
> irb> a.welcome_f
> hello, welcome to f method!
> => nil
> irb> b.welcome_f
> hajimemashite, welcome to f method!
> irb> def a.welcome_g; puts self + ", welcome to g method!"; end; end
> => nil

I can't find the opening class statement that seems to belong to the the 
2nd "end".
Or is irb so forgiving?
But interesting here seems to be that you explicitly specify the object 
"a" as "receiver" in your definition of method welcome_g.
Is this what makes it a "singleton"?
I haven't yet read enough about this concept.
In some way it looks to me as some sort of privatizing data an methods 
to a certain object (what sets it apart from the "private" protector?).

> irb> a.welcome_g
> hello, welcome to g method!
> => nil
> irb> b.welcome_g
> NoMethodError: undefined method 'g' for "hajimemashite":String
> 
> The welcome_g method for the object a is called a singleton method.
> It applies only to a.
> 
> There are obvious risks in opening up core classes (like String),
> especially if you modify them instead of just adding to them.  Even
> adding to classes after the fact is somewhat dangerous because of
> possible clashes with gems that you use, or sometimes even with your
> own code!

As already replied to Stefano,
it will certainly take quite a while until I would be confident enough
to mess about with core classes.

> 
>> As for style, shouldn't Ruby class definitions just as one
>> class-end block go into a single file instead of these break ups?
> 
> That's almost certainly up to you.

Yes, but don't Rubyists promote a certain style guide?
(Perlists are pretty picky about it, contrary to the language's public 
conception)


-- 
Posted via http://www.ruby-forum.com/.