Skip to content

Instantly share code, notes, and snippets.

@okabe-yuya
Created September 25, 2022 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okabe-yuya/d71ae4a0273606cb913eee4d19015067 to your computer and use it in GitHub Desktop.
Save okabe-yuya/d71ae4a0273606cb913eee4d19015067 to your computer and use it in GitHub Desktop.
# 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