Class: Braingasm::PrefixStack

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/braingasm/prefixes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrefixStack

Returns a new instance of PrefixStack.



10
11
12
# File 'lib/braingasm/prefixes.rb', line 10

def initialize
  @stack = []
end

Instance Attribute Details

#stackObject

Returns the value of attribute stack.



7
8
9
# File 'lib/braingasm/prefixes.rb', line 7

def stack
  @stack
end

Instance Method Details

#fix_params(function, default_param = 1) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/braingasm/prefixes.rb', line 14

def fix_params(function, default_param=1)
  prefix = @stack.pop || default_param

  case prefix
  when Integer, String
    function.curry.call(prefix)
  when Proc
    proc do |m|
      n = prefix.call(m)
      function.call(n, m)
    end
  end
end