Skip to content

Instantly share code, notes, and snippets.

@paneq
Forked from LTe/me_gusta.rb
Created February 26, 2012 10:27
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 paneq/1915895 to your computer and use it in GitHub Desktop.
Save paneq/1915895 to your computer and use it in GitHub Desktop.
Challenge
class TestUser
def is_ok?
true
end
def receive_message
yield("message", self)
end
def &(other)
TestUserGroup.new([self, other])
end
end
class TestUserGroup
attr_accessor :test_users
def initialize(users)
@test_users = users
end
def <<(other)
@test_users << other
end
def &(other)
self.class.new(@test_users + other)
end
def method_missing(method, *args, &block)
@test_users.map do |test_user|
test_user.send(method, *args, &block)
end
end
end
(bob & cindy).is_ok?
(bob & cindy).receive_message do |msg, user|
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