Class: JadePair
- Inherits:
-
Object
- Object
- JadePair
- Defined in:
- jade/jade_pair.rb
Overview
The JadePair is essential to the JadeObject. It stores two stings of first and second. Commonly the first is the variable name and the second is the variable data. JadePairs are used commonly throughout both the JadeSerializer and JadeDeserializer too.
Instance Attribute Summary collapse
-
#:first, :second(: first, : second) ⇒ Object
First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.
-
#first ⇒ Object
First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.
-
#second ⇒ Object
First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Checks whether the current instance of JadePair is empty Useful for preventing uses of nil JadePairs.
-
#eql?(other) ⇒ Boolean
Checks whether the current instance of JadePair is equal to another JadePair Useful for checking JadePair equivalence.
-
#initialize(first = nil, second = nil) ⇒ NilClass
constructor
Initializes the instance of both first and second.
-
#replace(first, second) ⇒ NilClass
Allows both the values of first and second to be replaced.
-
#replace_first(first) ⇒ NilClass
Allows the value of first to be replaced.
-
#replace_second(second) ⇒ NilClass
Allows the value of second to be replaced.
-
#to_array ⇒ String[]
to_array provides an array of both the values of first and second.
-
#to_str ⇒ String
to_str converts the current instance of the JadePair to a string.
Constructor Details
#initialize(first = nil, second = nil) ⇒ NilClass
Initializes the instance of both first and second. These default to nil if nothing is provided in the parameters.
26 27 28 29 |
# File 'jade/jade_pair.rb', line 26 def initialize(first = nil, second = nil) @first = first @second = second end |
Instance Attribute Details
#:first, :second(: first, : second) ⇒ Object
First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.
18 |
# File 'jade/jade_pair.rb', line 18 attr_accessor :first, :second |
#first ⇒ Object
First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.
18 19 20 |
# File 'jade/jade_pair.rb', line 18 def first @first end |
#second ⇒ Object
First and second are commonly used outside of the JadePair itself and therefore require an attribute accessor.
18 19 20 |
# File 'jade/jade_pair.rb', line 18 def second @second end |
Instance Method Details
#empty? ⇒ Boolean
Checks whether the current instance of JadePair is empty Useful for preventing uses of nil JadePairs
88 89 90 |
# File 'jade/jade_pair.rb', line 88 def empty? @first.nil? && @second.nil? end |
#eql?(other) ⇒ Boolean
Checks whether the current instance of JadePair is equal to another JadePair Useful for checking JadePair equivalence
98 99 100 101 |
# File 'jade/jade_pair.rb', line 98 def eql?(other) ((@first.eql? other.first) && (@second.eql? other.second)) end |
#replace(first, second) ⇒ NilClass
Allows both the values of first and second to be replaced.
36 37 38 39 40 |
# File 'jade/jade_pair.rb', line 36 def replace(first, second) @first = first @second = second nil end |
#replace_first(first) ⇒ NilClass
Allows the value of first to be replaced.
47 48 49 50 |
# File 'jade/jade_pair.rb', line 47 def replace_first(first) @first = first nil end |
#replace_second(second) ⇒ NilClass
Allows the value of second to be replaced.
57 58 59 60 |
# File 'jade/jade_pair.rb', line 57 def replace_second(second) @second = second nil end |
#to_array ⇒ String[]
to_array provides an array of both the values of first and second. This may be useful in some cases of JadeObject construction.
68 69 70 |
# File 'jade/jade_pair.rb', line 68 def to_array [@first, @second] end |
#to_str ⇒ String
to_str converts the current instance of the JadePair to a string. Useful when wanting a simple representation of the current JadePair.
78 79 80 |
# File 'jade/jade_pair.rb', line 78 def to_str "#{@first} : #{@second}" end |