Sha256: f982da9e2e0dcb390a05b86997eed542ede8da62e4d10d63a35233bf532739fb
Contents?: true
Size: 1.12 KB
Versions: 3
Compression:
Stored size: 1.12 KB
Contents
#Thanks to Ted Milken for updating the original example require_relative '../base/maroon_base.rb' #require_relative '../base/maroon/kernel.rb' #require_relative '../base/maroon/contracts.rb' class Person attr_accessor :name attr_accessor :greeting end ctx, source = Context::define :Greet_Someone, :greet do role :greeter do welcome do self.greeting end end role :greeted do end greet do puts %{#{greeter.name}: "#{greeter.welcome}, #{greeted.name}!"} end end class Greet_Someone def initialize(greeter, greeted) @greeter = greeter @greeted = greeted end end p source p1 = Person.new p1.name = 'Bob' p1.greeting = 'Hello' p2 = Person.new p2.name = 'World!' p2.greeting = 'Greetings' #Execute is automagically created for the default interaction (specified by the second argument in context :Greet_Someone, :greet do) #Executes construct a context object and calls the default interaction on this object #Greet_Someone.assert_that(p1).can_play(:greeter) #constructs a Greet_Someone context object and executes greet. Greet_Someone.new(p2, p1).greet
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
maroon-0.7.1 | Examples/greeter.rb |
maroon-0.7.0 | Examples/greeter.rb |
maroon-0.6.5 | Examples/greeter.rb |