Add method implementation for object instance : Virtual method « Class « Ruby






Add method implementation for object instance


class Button
  def pushed
  end
end

buttonA = Button.new
def buttonA.pushed
  puts "BBB"
end

buttonB = Button.new
def buttonB.pushed
  puts "AAA"
end


Button.new.pushed
#

buttonA.pushed
# BBB

buttonB.pushed
# AAA

 








Related examples in the same category

1.Virtual method Demo