Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

[Pull] Failure for multiple child classes hooking the same method

#5

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).

Reported by Star Trader · January 8th, 2009 @ 10:07 PM

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. Star Trader
    Star Trader
    • 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

    January 9th, 2009 @ 02:56 PM

  2. Dan Kubb (dkubb)
    Dan Kubb (dkubb)
    • State changed from new to resolved

    January 15th, 2009 @ 03:44 AM

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.