JSStack 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/js_stack.rb +41 -0
  3. data/lib/stack_node.rb +8 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75c4ccfc836f9c52a0555dc4a6ad1f5d8f380434
4
+ data.tar.gz: 03a475285457f2bcb359b1463a9afc705cccc0b0
5
+ SHA512:
6
+ metadata.gz: eabc1dca3501822b38aff893c017eccf6010a07044b2d91234aed06e968ff0f5882b29692eeff76d45fe85679badddaf54631f2ca67494f746c31a586415dcb9
7
+ data.tar.gz: 0f84f4a42697ce637b99a081e14b073a1015dad68278826f87f430d201c5680c250a9e0325da49943e5f2c208830b5677d3c5aadffcf373fa2a1972fc5ef5036
data/lib/js_stack.rb ADDED
@@ -0,0 +1,41 @@
1
+ require_relative 'stack_node'
2
+
3
+ class JSStack
4
+ attr_accessor :top
5
+
6
+ ##
7
+ # Creates a new stack with an optional first item +data+.
8
+ def initialize(data=nil)
9
+ @top = StackNode.new data unless data.nil?
10
+ @top ||= nil
11
+ end
12
+
13
+ ##
14
+ # Pushes the +data+ value provided on to the +top+ of the stack.
15
+ def push(data)
16
+ node = StackNode.new data
17
+ node.next = @top
18
+ @top = node
19
+ end
20
+
21
+ ##
22
+ # Pops the +top+ value off of the stack and returns it.
23
+ def pop
24
+ return if @top.nil?
25
+ popped_top = @top.data
26
+ @top = @top.next
27
+ popped_top
28
+ end
29
+
30
+ ##
31
+ # Returns the +top+ value off of the stack without removing it.
32
+ def peek
33
+ @top.nil? ? nil : @top.data
34
+ end
35
+
36
+ ##
37
+ # Returns a Boolean indicating whether the stack is empty.
38
+ def empty?
39
+ @top.nil?
40
+ end
41
+ end
data/lib/stack_node.rb ADDED
@@ -0,0 +1,8 @@
1
+ class StackNode
2
+ attr_accessor :data, :next
3
+
4
+ def initialize(data, next_node=nil)
5
+ @data = data
6
+ @next = next_node
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: JSStack
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Saint Jacque
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple stack data structure in Ruby.
14
+ email: joshsaintjacque@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/js_stack.rb
20
+ - lib/stack_node.rb
21
+ homepage: http://rubygems.org/gems/jsqueue
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.6
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A simple stack data structure in Ruby.
45
+ test_files: []