Class: Chainer::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/chainer/method.rb

Overview

Pipes method names on a context class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, value) ⇒ Method

Initializes pipe wrapper

Parameters:

  • context (Object)

    Context to call piped methods on

  • value (Object)

    Value to pass to the next method in the pipe



17
18
19
20
21
# File 'lib/chainer/method.rb', line 17

def initialize(context, value)
  @context = context
  @value = value.is_a?(self.class) ? value.value : value
  freeze
end

Instance Attribute Details

#contextObject (readonly)

Returns Context to call piped methods on.

Returns:

  • (Object)

    Context to call piped methods on



11
12
13
# File 'lib/chainer/method.rb', line 11

def context
  @context
end

#valueObject (readonly)

Returns the value of attribute value.



11
# File 'lib/chainer/method.rb', line 11

attr_reader :context, :value

Instance Method Details

#>>(method_name) ⇒ self

The “pipe” operator. Calls passed object with the wrapped value

Parameters:

  • method_name (Symbol)

    Method name to be called on the context object

Returns:

  • (self)

    Wrapped result of calculations



28
29
30
# File 'lib/chainer/method.rb', line 28

def >>(method_name) # rubocop:disable Style/OpMethod
  self.class.new context, context.send(method_name, value)
end