Stefano Crocco wrote:
> Alle martedì 24 luglio 2007, Ralph Grothe ha scritto:
>> That's where my first question arose.
>> Being used to the Perl debugger for similar experiments like with irb,
>> the former at least offers, albeit moderate, history amenities (viz.
>> !cmd#, to repeat cmd No. #)
>> I would have expected irb to offer some readline and thus command
>> history support (I am a lousy typer)?
> 
> irb does have readline support, but it's not enabled by default. One way 
> to do
> this is to pass the --readline option to irb (see irb -h for other 
> options).
> According to the first version of the pickaxe (I don't have the second 
> one),
> you should be able to do this also by setting IRB.conf[:USE_READLINE] to 
> true
> in your .irbrc, but I'm not sure this information is up to date. Since 
> you
> just bought the book you can look there for more information. Another
> possibility is to use wirble (http://raa.ruby-lang.org/project/wirble/).
>

Hi Stefano,

I fear my ruby build on hpux doesn't currently contain readline support
because I wasn't aware that I obviously was required to signal make that
I wished so.
When I start irb with --readline it doesn't seem to show any effect
(e.g. promoted tab completion or command history missing)
Although I am a lucky owner of the 2nd ed. of Pickaxe (which cover Ruby 
1.8)
I haven't yet come accross every chapter despite occassional flipping 
(it's such a tome)
In my volume chpt. 15 deals on IRB, but I haven't yet fumbled up a 
$HOME/.irbrc
let alone hacked the IRB class.

How can I verify if my ruby build lacks or supplies readline support?

I came accross that Config module (btw, Perl has a namesake which 
imports per default (I see Rubyists frown upon such namespace pollution) 
a tied hash called %Config).
So I hoped to find, case ignoring, any key that hopefully somewhat 
intuitively named by this module's author could contain the string read.
But this futile attempt doesn't hit:

$ ruby -r rbconfig -e 'include Config;puts 
CONFIG.keys.grep(/read/i).sort.join("\n")'

Btw, not having delved into the Modules chapter yet,
why am I supposed to require *and* include here?


> If I understand correctly your question, I'd say it's the latter.
> You can't add functionality to a method by redefining it: redefining a 
> method
> overwrites the previous definition:

Well, I am by far no OO expert, and Perl's OO implementation
of OO is very liberal indeed for the Purists' taste.

But redefination of a method from a derived class is actually what you 
do,
if you aren't please with its functionality, so I thought.
While those methods you are happy with you simply inherit.


> 
> class C
> 
>   def a_method
>     puts "this is the first definition"
>   end
> 
>   def a_method
>     puts "this is the first definition"
>   end

I asume a typo here,
you probably meant "this is the  second definition"?

> 
> end
> 
> C.new.a_method
> => "this is the second definition"
> 
> On the other hand, you can reopen a class to add other methods or 
> constants
> (or to redefine already defined methods):


Well, I think what confused me is the "strange" terminology.
I simply didn't know the concept of "reopening a class".

> 
> class C
> 
>   def method_1
>     puts "this is method_1"
>   end
> 
> end
> 
> # some other code
> 
> class C
> 
>   def method_2
>     puts "this is method_2"
>   end
> 
> end
> 
> C.new.method_1
> => "this is method_1"
> 
> C.new.method_2
> => "this is method_2"
> 
>> Is this really all that easy?
> It is, but you need to be careful. If you only want to add new methods, 
> then
> it's most likely ok, but if you want to modify already existing methods, 
> then
> you can get in trouble, because other libraries (including the ruby 
> standard
> library) expect those methods to behave in a certain way and will break 
> if
> they don't.

I won't be doing this, at least for quite some while until I
master Ruby enough (will I ever?).

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