Iain Barnett wrote:
Verbatim (again):
$ irb
r = [1..99, 100..199]
=> [1..99, 100..199]
xs = r.local_methods
If that's verbatim, then how is your local_methods method getting
loaded? Are you preloading stuff in .irbrc? What other stuff do you have
in there? Try removing it all.
The next thing is, what exact version of ruby are you using? I'm
guessing some variant of 1.9.X, because you are getting symbols. Bugs
in older versions of 1.9 are, ahem, not unknown.
But I can't replicate your problem with the two versions I have here:
$ cat locmeth.rb
class Object
def local_methods
(methods - Object.instance_methods).sort
end
end
$ cat extarray.rb
class Array
def index_in_range( n )
self.each_with_index do |x, i|
return i if x === n
end
return nil
end
end
$ ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]
$ irb --simple-prompt
RUBY_VERSION
=> "1.8.6"
r = [1..99, 100..199]
=> [1..99, 100..199]
xs = r.local_methods
NoMethodError: undefined method `local_methods' for [1..99,
100..199]:Array
from (irb):3
require 'locmeth'
=> true
xs = r.local_methods
=> ["&", "*", "+", "-", "<<", "<=>", "", "=", "all?", "any?",
"assoc", "at", "clear", "collect", "collect!", "compact", "compact!",
"concat", "delete", "delete_at", "delete_if", "detect", "each",
"each_index", "each_with_index", "empty?", "entries", "fetch", "fill",
"find", "find_all", "first", "flatten", "flatten!", "grep", "include?",
"index", "indexes", "indices", "inject", "insert", "join", "last",
"length", "map", "map!", "max", "member?", "min", "nitems", "pack",
"partition", "pop", "push", "rassoc", "reject", "reject!", "replace",
"reverse", "reverse!", "reverse_each", "rindex", "select", "shift",
"size", "slice", "slice!", "sort", "sort!", "sort_by", "to_ary",
"transpose", "uniq", "uniq!", "unshift", "values_at", "zip", "|"]
load 'extarray.rb'
=> true
r.local_methods - xs
=> ["index_in_range"]
And here's what I get with the particular variant of 1.9 I have lying
around, a 1.9.2 preview from last year:
$ ruby19 -v
ruby 1.9.2dev (2009-07-18 trunk 24186) [i686-linux]
$ irb19 --simple-prompt
r = [1..99, 100.199]
=> [1..99, 100.199]
require 'locmeth'
LoadError: no such file to load -- locmeth
from (irb):2:in `require'
from (irb):2
from /usr/local/bin/irb19:12:in `<main>'
load 'locmeth.rb'
=> true
xs = r.local_methods
=> [:&, :*, :+, :-, :<<, :<=>, :, :=, :all?, :any?, :assoc, :at,
:clear, :collect, :collect!, :combination, :compact, :compact!, :concat,
:count, :cycle, :delete, :delete_at, :delete_if, :detect, :drop,
:drop_while, :each, :each_cons, :each_index, :each_slice,
:each_with_index, :each_with_object, :empty?, :entries, :fetch, :fill,
:find, :find_all, :find_index, :first, :flatten, :flatten!, :grep,
:group_by, :include?, :index, :inject, :insert, :join, :last, :length,
:map, :map!, :max, :max_by, :member?, :min, :min_by, :minmax,
:minmax_by, :none?, :one?, :pack, :partition, :permutation, :pop,
:product, :push, :rassoc, :reduce, :reject, :reject!, :replace,
:reverse, :reverse!, :reverse_each, :rindex, :sample, :select, :shift,
:shuffle, :shuffle!, :size, :slice, :slice!, :sort, :sort!, :sort_by,
:sort_by!, :take, :take_while, :to_a, :to_ary, :transpose, :uniq,
:uniq!, :unshift, :values_at, :zip, :|]
load 'extarray.rb'
=> true
r.local_methods - xs
=> [:index_in_range]
These are on a 32-bit Ubuntu Linux Hardy system.
So if the problem is repeatable in your environment, you'll need to dig
a bit further to see what's causing it. Possible problems are:
(1) There are multiple versions of extensions/Array.rb reachable from
your $LOAD_PATH, and you're not loading the one you expect. At some
point in 1.9 development, "." was removed from $LOAD_PATH.
(2) There's something odd in .irbrc
Incidentally, there also seems to be some other problem which is
preventing symbols like :& :* and :+ from appearing in your posting, by
the time it reaches ruby-forum.com at least. Possibly something to do
with copy-paste and/or HTML escaping.
Regards,
Brian.
···
from :0
--
Posted via http://www.ruby-forum.com/\.