On 17 Aug 2010, at 15:36, Brian Candler wrote:

> Iain Barnett wrote:
>> So why did it produce two different outputs even though my patch =
didn't=20
>> add a rand
>=20
> I've no idea, because you haven't shown the source of your=20
> "local_methods" method,

class Object
  def local_methods
    (methods - Object.instance_methods).sort
  end
end


> nor the exact sequence of operations to get to=20
> that point.
>=20

The exact sequence is below, it's what I posted earlier.

> If you were in a single irb session, and did load =
'extensions/Array.rb'=20
> after changing Array.rb, then any methods added to Array by the old=20
> version will still be present in Array, even if the new Array.rb =
doesn't=20
> define them.

I quit the irb session, I quit the terminal, I made sure there was no =
ruby process running on the system.

>=20
>> and why doesn't my patch even seem to work anymore?
>=20
> "Doesn't work" is not a helpful description of an error.

There is no error, I already gave a full description and everything that =
came back except for local_methods.

>=20
> Post your current code (preferably boiled down to the smallest =
runnable=20
> example which replicates it). Show exactly what you type, exactly what=20=

> you see - results and/or error message - and what you were expecting =
to=20
> see.

Verbatim (again):

$ irb
> r =3D [1..99, 100..199]
=3D> [1..99, 100..199]
> xs =3D r.local_methods=20
=3D> [:, :, :, :-, :, :=3D>, :[], :[], :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!, :fold, =
: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, =
:take, :take_while, :to_a, :to_ary, :transpose, :uniq, :uniq!, :unshift, =
:values_at, :zip, :]
> load 'extensions/Array.rb'
=3D> true
> r.local_methods - xs
=3D> [:rand]

This is extensions/Array.rb

class Array

 def index_in_range( n )
   self.each_with_index do |x, i|
     return i if x =3D=3D=3D n
   end
   return nil
 end


end

I'm not expecting to see rand in the list of public methods brought back =
by r.local_methods. I've even since moved the extensions/Array.rb to a =
new location.



Regards,
Iain