Add method implementation for object instance : Virtual method « Class « Ruby
- Ruby
- Class
- Virtual method
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