class Strategize::Operation

Operations let you define a block of code that you would like to execute, and by calling process with a subject you can tell the operation what object you would like to execute the code against.

Operations are similar to Rules, but the block of code that you pass in the constuctor does not have to be a predicate function.

Attributes

function[R]

@attr_reader function A Proc or Lambda describing the code to be executed

name[R]

@attr_reader name a descriptive name for the operation

Public Class Methods

new(name, function) click to toggle source

Create a new instance of Operation

@param name [Symbol] a descriptive name for the operation @param function [Proc] the code to be executed @return [Operation]

# File lib/strategize/operations/operation.rb, line 20
def initialize(name, function)
  unless function.respond_to?(:call)
    raise InvalidFunctionError, 'Invalid function in Operation'
  end

  @name = name
  @function = function
end

Public Instance Methods

process(subject) click to toggle source

Execute the function against a specific object

@param subject [Object] will become self when executing the function @return [void]

# File lib/strategize/operations/operation.rb, line 33
def process(subject)
  subject.instance_exec(&@function)
end