class Newral::Functions::Block

as its ruby we of course have to also offer the possibility for blocks the block is called in calculate, always passing the current @params values however for more complex examples you should rather derive from Base

Public Class Methods

new( directions:0, params:[], &block ) click to toggle source
# File lib/newral/functions/block.rb, line 12
def initialize( directions:0, params:[], &block )
  raise Errors::NoBlock unless block_given?
  @calculate_block = block
  @params = params
  @directions = directions || params.size
end

Public Instance Methods

calculate( input ) click to toggle source
# File lib/newral/functions/block.rb, line 19
def calculate( input ) 
  @calculate_block.call input, @params 
end
move( direction: 0, step:0.01, step_percentage: nil ) click to toggle source
# File lib/newral/functions/block.rb, line 23
def move( direction: 0, step:0.01, step_percentage: nil )
  raise Errors::InvalidDirection unless direction >=0 && direction<@directions
  @params[direction]=(step_percentage ? @params[direction]*(1+step_percentage.to_f/100) : @params[direction]+step )
  self
end
number_of_directions() click to toggle source
# File lib/newral/functions/block.rb, line 29
def number_of_directions 
  @directions
end