Class: ExcADG::Payload::Example::Multiplier

Inherits:
Object
  • Object
show all
Includes:
ExcADG::Payload
Defined in:
lib/excadg/payload/example.rb

Overview

calculate Nth member of the function y = x(n) * (x(n-1)) where x(0) = 0 and x(1) = 1 it illustrates how payload can be customized with @args and extended by adding methods

Instance Attribute Summary

Attributes included from ExcADG::Payload

#args

Instance Method Summary collapse

Methods included from ExcADG::Payload

#initialize

Instance Method Details

#getObject



64
65
66
# File 'lib/excadg/payload/example.rb', line 64

def get
  -> { get_el x: @args }
end

#get_el(x:) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/excadg/payload/example.rb', line 68

def get_el x:
  case x
  when 0 then 0
  when 1 then 1
  else
    x * get_el(x: x - 1)
  end
end