Return to Snippet

Revision: 42545
at March 7, 2011 00:14 by Shamaoke


Initial Code
# encoding: utf-8

class Parent
  attr_reader :one, :two
end

class FirstChild < Parent
  def initialize
    @one = 'first one'
    @two = 'first two'
  end
end

class SecondChild < Parent
  def initialize
    @one = 'second one'
    @two = 'second two'
  end
end

one = Parent.new.method(:one).unbind
two = Parent.new.method(:two).unbind

puts one.bind(FirstChild.new).call  #=> first one
puts two.bind(FirstChild.new).call  #=> first two

puts one.bind(SecondChild.new).call #=> second one
puts two.bind(SecondChild.new).call #=> second two

Initial URL

                                

Initial Description

                                

Initial Title
Bind the parent's method to the child objects

Initial Tags
ruby

Initial Language
Ruby