Sha256: fc51c4998012328556236a8a2c7296ad753c9537783c42fb0476b58c5fc13bcb

Contents?: true

Size: 1020 Bytes

Versions: 3

Compression:

Stored size: 1020 Bytes

Contents

#Thanks to Ted Milken for updating the original example

require '../lib/maroon.rb'
require '../lib/maroon/kernel.rb'

class Person
  attr_accessor :name
  attr_accessor :greeting
end

context :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

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 construc a context object and calls the default interaction on this object
Greet_Someone.execute p1, p2
#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.6.1 Examples/greeter.rb
maroon-0.6.0 Examples/greeter.rb
maroon-0.5.3 Examples/greeter.rb