-
-
Save LTe/1816178 to your computer and use it in GitHub Desktop.
Challenge
This file contains hidden or 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
class TestUser | |
def is_ok? | |
true | |
end | |
def receive_message | |
yield("user", "message") | |
end | |
def &(other) | |
test_user_group = TestUserGroup.new(self) | |
test_user_group << other | |
test_user_group | |
end | |
end | |
class TestUserGroup | |
attr_accessor :test_users | |
def initialize(user) | |
@test_users = [user] | |
end | |
def <<(other) | |
(@test_users ||= []) << other | |
end | |
def &(other) | |
<<(other) | |
end | |
def method_missing(method, *args, &block) | |
result = [] | |
@test_users.each do |test_user| | |
result << test_user.send(method, *args, &block) | |
end | |
result | |
end | |
end |
This file contains hidden or 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
(bob & cindy).is_ok? | |
(bob & cindy).receive_message do |user, message| | |
end | |
TestUser === bob.class | |
TestUserGroup === (bob & cindy).class |
This file contains hidden or 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
[bob, cindy].each do |user| | |
user.is_ok? | |
user.receive_message do |msg| | |
end | |
end | |
TestUser === bob.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment