Class: Agents::Action
- Inherits:
-
Object
- Object
- Agents::Action
- Defined in:
- lib/actions/action.rb
Overview
Takes a block and executes it when the action is called.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#call(args) ⇒ Object
Execute the block with the given arguments.
- #for_prompt ⇒ Object
-
#initialize(name:, description: "", arguments: [], examples: [], &block) ⇒ Action
constructor
Create a new action.
Constructor Details
#initialize(name:, description: "", arguments: [], examples: [], &block) ⇒ Action
Create a new action
13 14 15 16 17 18 19 |
# File 'lib/actions/action.rb', line 13 def initialize(name:, description: "", arguments: [], examples: [], &block) @name = name @description = description @arguments = arguments @examples = examples @block = block end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def arguments @arguments end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def description @description end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def examples @examples end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def name @name end |
Instance Method Details
#call(args) ⇒ Object
Execute the block with the given arguments.
22 23 24 |
# File 'lib/actions/action.rb', line 22 def call(args) @block.call(args) end |
#for_prompt ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/actions/action.rb', line 26 def for_prompt s = "#{name}: #{description}\n" unless arguments.empty? s << " Arguments:\n" s << arguments.collect(&:for_prompt).join("\n") << "\n" end unless examples.empty? s << " For example:\n" s << examples.collect(&:for_prompt).join("\n") << "\n" end s end |