Re: Spira: method resolution of has_many resources not working sometimes

I have looked more into this over the last days.  

On Fri, May 20, 2011 at 12:11:10PM -0500, Ben Lavender wrote:
> This is a quirk of Promise. In Ruby 1.8, there is no BasicObject, so
> Promise fakes it by undefining all of the non-critical methods on
> Object. 

This is a part that actually fails in 1.8.7.  The reason is that
instance_methods() returns an array of strings in 1.8 and an array of symbols
in 1.9.  And undef_methods silently fails if passed a string instead of a
symbol.

Using

  instance_methods.each { |m| undef_method m.to_sym unless m.to_s =~ /__/ }
                                            ^^^^^^^
in promise.rb brings us forward a big step to a solution.

The other thing is that the test case is wrong for 1.8.7.  Promise must
be required *after* Object has been modified because it only undefs the
instance methods that are defined on Object when promise.rb is executed.

class Object
  def to_zorch
    "promises can't be zorched!"
  end
end

require 'promise'

class Fixnum
  def to_zorch
    to_s
  end
end
x = promise { 15 }
x.to_zorch

With the above change to promise.rb I now get '15' on 1.8.7 too.

Of course, this does not produce exactly the same behaviour as under 1.9.x.
A quick test suggests it may be enough to make Spira and Rails work on 1.8.7.

--chris

Received on Wednesday, 25 May 2011 16:59:19 UTC