Module: Trith::Core::Stack::Shufflers

Defined in:
lib/trith/core/stack.rb

Overview

Stack shufflers.

Instance Method Summary (collapse)

Instance Method Details

- (Machine) clear

Returns:



10
11
12
13
# File 'lib/trith/core/stack.rb', line 10

def clear
  @stack.clear
  self
end

- (Machine) depth

Returns:



17
18
19
# File 'lib/trith/core/stack.rb', line 17

def depth
  push(@stack.size)
end

- (Machine) drop

Returns:



46
47
48
49
# File 'lib/trith/core/stack.rb', line 46

def drop
  pop
  self
end

- (Machine) drop2

Returns:



53
54
55
56
# File 'lib/trith/core/stack.rb', line 53

def drop2
  pop(2)
  self
end

- (Machine) drop3

Returns:



61
62
63
64
# File 'lib/trith/core/stack.rb', line 61

def drop3
  pop(3)
  self
end

- (Machine) dup

Returns:



69
70
71
# File 'lib/trith/core/stack.rb', line 69

def dup
  push(*(pop(1) * 2))
end

- (Machine) dup2

Returns:



75
76
77
# File 'lib/trith/core/stack.rb', line 75

def dup2
  push(*(pop(2) * 2))
end

- (Machine) dup3

Returns:



82
83
84
# File 'lib/trith/core/stack.rb', line 82

def dup3
  push(*(pop(3) * 2))
end

- (Machine) nip

Returns:



95
96
97
# File 'lib/trith/core/stack.rb', line 95

def nip
  push(pop(2).last)
end

- (Machine) nip2

Returns:



101
102
103
# File 'lib/trith/core/stack.rb', line 101

def nip2
  push(pop(3).last)
end

- (Machine) over

Returns:



108
109
110
# File 'lib/trith/core/stack.rb', line 108

def over
  push(*((ops = pop(2)) + [ops.first]))
end

- (Machine) pick

Returns:



114
115
116
# File 'lib/trith/core/stack.rb', line 114

def pick
  push(*((ops = pop(3)) + [ops.first]))
end

- (Machine) rot(a, b, c)

Returns:



120
121
122
# File 'lib/trith/core/stack.rb', line 120

def rot(a, b, c)
  push(b, c, a)
end

- (Machine) stack_

Returns:



23
24
25
26
# File 'lib/trith/core/stack.rb', line 23

def stack_
  @stack = [@stack]
  self
end

- (Machine) swap

Returns:



89
90
91
# File 'lib/trith/core/stack.rb', line 89

def swap
  push(*pop(2).reverse)
end

- (Machine) unstack(seq)

Parameters:

  • (#to_a, #each)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/trith/core/stack.rb', line 31

def unstack(seq)
  @stack = case seq
    when String then seq.each_char.to_a
    when Array  then seq
    else case
      when seq.respond_to?(:to_a) then seq.to_a
      when seq.respond_to?(:each) then seq.each.to_a
      else raise Machine::InvalidOperandError.new(seq, :unstack)
    end
  end
  self
end