On Sunday, March 30, 2003, 11:41:20 PM, Gavin wrote:

> All you needed to know was that irb uses "Readline" to do command-line
> manipulation (including history), then look up Nutshell to see that
> Readline::HISTORY is where it's at.  Doesn't sound thread-safe.


Readline::HISTORY is an Object.  Nutshell says it behaves like an
Array.  But it doesn't #to_s like an array of strings, nor does it
recognise #size.

Here are the methods it has in common with Array, excluding methods
inherited from Object:

["push", "length", "each", "shift", "empty?", "[]", "delete_at",
"pop", "[]=", "<<", "member?", "sort", "collect", "detect", "max",
"entries", "reject", "each_with_index", "find", "min", "select",
"include?", "grep", "map", "find_all"]

Here are the Array methods that Readline::HISTORY _doesn't_ have:

["clear", "&", "reverse", "sort!", "slice", "<=>", "uniq!",
"delete_if", "*", "indexes", "nitems", " +", "rindex", "last",
"rassoc", "filter", "each_index", "flatten", "-", "at", "fill",
"reverse!", "collect!", "slice!", "|", "compact", "reject!",
"indices", "uniq", "replace", "reverse_each", "to_ary", "flatten!",
"pack", "index", "join", "concat", "first", "delete", "assoc", "size",
"map!", "unshift", "compact!"]


Can anyone comment (speculation accepted) why the Readline class does
not simply use an Array for its HISTORY?  If it's a matter of
write-access, it would be more elegant to write a module
ReadOnlyArray, that redefines/removes the appropriate methods, so that
this module can be reused.

I'm looking at the source code, but since it's in C I doubt it will
enlighten me much.

Cheers,
Gavin