Module: Trith::Core::Stack::Shufflers
- Defined in:
- lib/trith/core/stack.rb
Overview
Stack shufflers.
Instance Method Summary (collapse)
- - (Machine) clear
- - (Machine) depth
- - (Machine) drop
- - (Machine) drop2
- - (Machine) drop3
- - (Machine) dup
- - (Machine) dup2
- - (Machine) dup3
- - (Machine) nip
- - (Machine) nip2
- - (Machine) over
- - (Machine) pick
- - (Machine) rot(a, b, c)
- - (Machine) stack_
- - (Machine) swap
- - (Machine) unstack(seq)
Instance Method Details
- (Machine) clear
10 11 12 13 |
# File 'lib/trith/core/stack.rb', line 10 def clear @stack.clear self end |
- (Machine) depth
17 18 19 |
# File 'lib/trith/core/stack.rb', line 17 def depth push(@stack.size) end |
- (Machine) dup2
75 76 77 |
# File 'lib/trith/core/stack.rb', line 75 def dup2 push(*(pop(2) * 2)) end |
- (Machine) dup3
82 83 84 |
# File 'lib/trith/core/stack.rb', line 82 def dup3 push(*(pop(3) * 2)) end |
- (Machine) nip2
101 102 103 |
# File 'lib/trith/core/stack.rb', line 101 def nip2 push(pop(3).last) end |
- (Machine) over
108 109 110 |
# File 'lib/trith/core/stack.rb', line 108 def over push(*((ops = pop(2)) + [ops.first])) end |
- (Machine) pick
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)
120 121 122 |
# File 'lib/trith/core/stack.rb', line 120 def rot(a, b, c) push(b, c, a) end |
- (Machine) stack_
23 24 25 26 |
# File 'lib/trith/core/stack.rb', line 23 def stack_ @stack = [@stack] self end |
- (Machine) swap
89 90 91 |
# File 'lib/trith/core/stack.rb', line 89 def swap push(*pop(2).reverse) end |
- (Machine) unstack(seq)
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 |