[Pull] Failure for multiple child classes hooking the same method
Reported by Star Trader | January 8th, 2009 @ 10:07 PM
This is a duplicate of Datamapper bug #759
require 'extlib'
class Person
include Extlib::Hook
attr_accessor :name
def valid?
!name.nil?
end
end
class Man < Person
before :valid?, :val
def val
self.name ||= "Anonymous Guy"
end
end
class Woman < Person
before :valid?, :val
def val
self.name ||= "Anonymous Gal"
end
end
puts "A Person with no name fails:"
puts Person.new.valid? #=> false
puts "A Man with no name Succeeds:"
m = Man.new
puts m.valid? #=> true
puts "A Woman with no name should Succeeds but does not:"
w = Woman.new
puts w.valid? #=> false (!?)
When two or more classes inherit from a root class and try to hook into the same method all after the first fail to to call the hooked method.
A work-around is to define the hook and method in the root class (e.g. Person).
Comments and changes to this ticket
-
Star Trader January 9th, 2009 @ 02:56 PM
- Title changed from Failure for multiple child classes hooking the same method to [Pull] Failure for multiple child classes hooking the same method
I have fixed this bug in my fork of extlib at github.com/startrader/extlib. Test cases included
-
Dan Kubb (dkubb) January 15th, 2009 @ 03:44 AM
- State changed from new to resolved
This was resolved by:
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Lightweight fast Ruby core extensions library for DataMapper and Merb.