Created
September 25, 2022 12:11
-
-
Save okabe-yuya/d71ae4a0273606cb913eee4d19015067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Your code here! | |
class Notify | |
def exec(*data) | |
raise NotImplementedError.new("#{self.class}##{__method__} が実装されていません") | |
end | |
end | |
class User< Notify | |
def exec(*data) | |
puts "send to User #{data}" | |
end | |
end | |
class AdminUser < Notify | |
def exec(*data) | |
puts "send to AdminUser #{data}" | |
end | |
end | |
class Subscribe | |
def initialize | |
@subscribers = [] | |
end | |
def set(ins) | |
@subscribers.push(ins) | |
self | |
end | |
def exec(*data) | |
@subscribers.each { |ins| ins.exec(*data) } | |
end | |
end | |
sub = Subscribe.new() | |
sub.set(User.new).set(AdminUser.new).set(User.new).set(AdminUser.new).set(User.new) | |
sub.exec("🌵", "🐎") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment