Class: SXP::Pair

Inherits:
Object show all
Defined in:
lib/sxp/pair.rb

Direct Known Subclasses

List

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Pair) initialize(head = nil, tail = nil)

A new instance of Pair

Parameters:

  • (Object) head (defaults to: nil)
  • (Object) tail (defaults to: nil)


13
14
15
# File 'lib/sxp/pair.rb', line 13

def initialize(head = nil, tail = nil)
  @head, @tail = head, tail
end

Instance Attribute Details

- (Object) head

Returns:



5
6
7
# File 'lib/sxp/pair.rb', line 5

def head
  @head
end

- (Object) tail

Returns:



8
9
10
# File 'lib/sxp/pair.rb', line 8

def tail
  @tail
end

Instance Method Details

- (Boolean) dotted?

Returns true if the tail of this pair is not nil or another pair.



30
31
32
# File 'lib/sxp/pair.rb', line 30

def dotted?
  !proper?
end

- (Boolean) empty?

Returns true if the head and tail of this pair are both nil.

Returns:

  • (Boolean)


21
22
23
# File 'lib/sxp/pair.rb', line 21

def empty?
  head.nil? && tail.nil?
end

- (String) inspect

Returns a developer-friendly representation of this pair.

Returns:



55
56
57
58
59
60
61
62
# File 'lib/sxp/pair.rb', line 55

def inspect
  case
    when tail.nil?
      "(#{head.inspect})"
    else
      "(#{head.inspect} . #{tail.inspect})"
  end
end

- (Boolean) proper?

Returns true if the tail of this pair is nil or another pair.



39
40
41
# File 'lib/sxp/pair.rb', line 39

def proper?
  tail.nil? || tail.is_a?(Pair)
end

- (Array) to_a

Returns an array representation of this pair.

Returns:



47
48
49
# File 'lib/sxp/pair.rb', line 47

def to_a
  [head, tail]
end