Skip to content

Instantly share code, notes, and snippets.

@LTe
Forked from paneq/me_gusta.rb
Created February 13, 2012 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LTe/1816178 to your computer and use it in GitHub Desktop.
Save LTe/1816178 to your computer and use it in GitHub Desktop.
Challenge
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
(bob & cindy).is_ok?
(bob & cindy).receive_message do |user, message|
end
TestUser === bob.class
TestUserGroup === (bob & cindy).class
[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