Class: TDriver::StackableValue
- Defined in:
- lib/tdriver/util/common/stackable.rb
Instance Method Summary collapse
- #==(value) ⇒ Object (also: #eql?)
-
#[](value) ⇒ Object
TODO: document me.
-
#[]=(position, value) ⇒ Object
TODO: document me.
-
#count ⇒ Object
(also: #size)
TODO: document me.
-
#first ⇒ Object
TODO: document me.
-
#initialize(value, explicit_format = []) ⇒ StackableValue
constructor
TODO: document me.
-
#inspect ⇒ Object
TODO: document me.
-
#kind_of?(klass) ⇒ Boolean
TODO: document me.
-
#last ⇒ Object
(also: #value)
TODO: document me.
-
#pop ⇒ Object
TODO: document me.
-
#push(value) ⇒ Object
(also: #<<)
TODO: document me.
-
#restore ⇒ Object
TODO: document me.
-
#set(value) ⇒ Object
(also: #value=)
TODO: document me.
-
#stacked? ⇒ Boolean
TODO: document me.
-
#to_s ⇒ Object
TODO: document me.
Constructor Details
#initialize(value, explicit_format = []) ⇒ StackableValue
TODO: document me
25 26 27 28 29 30 31 32 33 |
# File 'lib/tdriver/util/common/stackable.rb', line 25 def initialize( value, explicit_format = [] ) @explicit_format = explicit_format.kind_of?( Array ) ? explicit_format : [ explicit_format ] @stack = [] push( value ) end |
Instance Method Details
#==(value) ⇒ Object Also known as: eql?
158 159 160 161 162 |
# File 'lib/tdriver/util/common/stackable.rb', line 158 def ==( value ) @stack.last == value end |
#[](value) ⇒ Object
TODO: document me
132 133 134 135 136 137 138 139 |
# File 'lib/tdriver/util/common/stackable.rb', line 132 def []( value ) # return last one if index is too high value = -1 if ( value > @stack.count - 1 ) @stack[ value ] end |
#[]=(position, value) ⇒ Object
TODO: document me
142 143 144 145 146 147 148 149 |
# File 'lib/tdriver/util/common/stackable.rb', line 142 def []=( position, value ) # return last one if index is too high value = -1 if ( position > @stack.count - 1 ) @stack[ position ] = value end |
#count ⇒ Object Also known as: size
TODO: document me
108 109 110 111 112 113 |
# File 'lib/tdriver/util/common/stackable.rb', line 108 def count # return size of the stack array @stack.count end |
#first ⇒ Object
TODO: document me
116 117 118 119 120 121 |
# File 'lib/tdriver/util/common/stackable.rb', line 116 def first # return first value in stack array @stack.first end |
#inspect ⇒ Object
TODO: document me
100 101 102 103 104 105 |
# File 'lib/tdriver/util/common/stackable.rb', line 100 def inspect # return inspect of last value in stack array @stack.last.inspect end |
#kind_of?(klass) ⇒ Boolean
TODO: document me
165 166 167 168 169 170 |
# File 'lib/tdriver/util/common/stackable.rb', line 165 def kind_of?( klass ) # compary stacked value class @stack.last.kind_of?( klass ) or klass == TDriver::StackableValue end |
#last ⇒ Object Also known as: value
TODO: document me
124 125 126 127 128 129 |
# File 'lib/tdriver/util/common/stackable.rb', line 124 def last # return last value in stack array @stack.last end |
#pop ⇒ Object
TODO: document me
64 65 66 67 68 69 70 71 |
# File 'lib/tdriver/util/common/stackable.rb', line 64 def pop @stack.pop unless ( @stack.count == 1 ) # return last value from stack @stack.last end |
#push(value) ⇒ Object Also known as: <<
TODO: document me
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tdriver/util/common/stackable.rb', line 36 def push( value ) unless @explicit_format.empty? found = false # collect verbose type list verbose_type_list = @explicit_format.each_with_index.collect{ | type, index | raise TypeError, "invalid argument type #{ type } for check_type. Did you mean #{ type.class }?" unless type.kind_of?( Class ) found = true if value.kind_of?( type ) # result string, separate types if multiple types given "#{ ( ( index > 0 ) ? ( index + 1 < @explicit_format.count ? ", " : " or " ) : "" ) }#{ type.to_s }" }.join raise TypeError, "wrong variable format #{ value.class } for stackable value (expected #{ verbose_type_list })" unless found end # add to stack @stack << value end |
#restore ⇒ Object
TODO: document me
74 75 76 77 78 79 80 81 |
# File 'lib/tdriver/util/common/stackable.rb', line 74 def restore @stack = [ @stack.first ] # return first value in stack array @stack.last end |
#set(value) ⇒ Object Also known as: value=
TODO: document me
152 153 154 155 156 |
# File 'lib/tdriver/util/common/stackable.rb', line 152 def set( value ) @stack[ -1 ] = value end |
#stacked? ⇒ Boolean
TODO: document me
84 85 86 87 88 89 |
# File 'lib/tdriver/util/common/stackable.rb', line 84 def stacked? # determine if there is values in stack @stack.count > 1 end |
#to_s ⇒ Object
TODO: document me
92 93 94 95 96 97 |
# File 'lib/tdriver/util/common/stackable.rb', line 92 def to_s # return last value in stack array as string @stack.last.to_s end |