Sha256: 5ff8afb564af110970346a7fca2bbcf9ad25dc1175ec814354d954d0bd4e01bc
Contents?: true
Size: 903 Bytes
Versions: 4
Compression:
Stored size: 903 Bytes
Contents
#!/usr/bin/env ruby require 'protocol' Assignable = Protocol do def assign_to(assignee) Assignee =~ assignee end end Assignee = Protocol do end Assignments = Protocol do implementation def assignments @assignable ||= [] end def add(assignable) Assignable =~ assignable assignments << assignable self end def assign(assignable, assignee) Assignable =~ assignable Assignee =~ assignee assignable.assign_to(assignee) add(assignable) end end class Task def assign_to(assignee) @assignee = assignee end conform_to Assignable end class Project conform_to Assignments conform_to Assignee end class User conform_to Assignments conform_to Assignee end p Project.new.assign(Task.new, User.new) p Project.new.assign(Task.new, Object.new) begin Project.new.assign(Object.new, Task.new) rescue Protocol::CheckError => e p e end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
protocol-2.0.1 | examples/assignments.rb |
protocol-2.0.0 | examples/assignments.rb |
protocol-1.0.1 | examples/assignments.rb |
protocol-1.0.0 | examples/assignments.rb |