Class: SXP::Pair
Direct Known Subclasses
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#dotted? ⇒ Boolean
Returns ‘true` if the tail of this pair is not `nil` or another pair.
-
#empty? ⇒ Boolean
Returns ‘true` if the head and tail of this pair are both `nil`.
-
#initialize(head = nil, tail = nil) ⇒ Pair
constructor
A new instance of Pair.
-
#inspect ⇒ String
Returns a developer-friendly representation of this pair.
-
#proper? ⇒ Boolean
Returns ‘true` if the tail of this pair is `nil` or another pair.
-
#to_a ⇒ Array
Returns an array representation of this pair.
Constructor Details
#initialize(head = nil, tail = nil) ⇒ Pair
Returns a new instance of Pair.
14 15 16 |
# File 'lib/sxp/pair.rb', line 14 def initialize(head = nil, tail = nil) @head, @tail = head, tail end |
Instance Attribute Details
Instance Method Details
#dotted? ⇒ Boolean
Returns ‘true` if the tail of this pair is not `nil` or another pair.
31 32 33 |
# File 'lib/sxp/pair.rb', line 31 def dotted? !proper? end |
#empty? ⇒ Boolean
Returns ‘true` if the head and tail of this pair are both `nil`.
22 23 24 |
# File 'lib/sxp/pair.rb', line 22 def empty? head.nil? && tail.nil? end |
#inspect ⇒ String
Returns a developer-friendly representation of this pair.
56 57 58 59 60 61 62 63 |
# File 'lib/sxp/pair.rb', line 56 def inspect case when tail.nil? "(#{head.inspect})" else "(#{head.inspect} . #{tail.inspect})" end end |
#proper? ⇒ Boolean
Returns ‘true` if the tail of this pair is `nil` or another pair.
40 41 42 |
# File 'lib/sxp/pair.rb', line 40 def proper? tail.nil? || tail.is_a?(Pair) end |
#to_a ⇒ Array
Returns an array representation of this pair.
48 49 50 |
# File 'lib/sxp/pair.rb', line 48 def to_a [head, tail] end |