Class: SXP::Pair

Inherits:
Object show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/pair.rb

Direct Known Subclasses

List

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head = nil, tail = nil) ⇒ Pair

Returns a new instance of Pair.

Parameters:

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


14
15
16
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/pair.rb', line 14

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

Instance Attribute Details

#headObject

Returns:



6
7
8
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/pair.rb', line 6

def head
  @head
end

#tailObject

Returns:



9
10
11
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/pair.rb', line 9

def tail
  @tail
end

Instance Method Details

#dotted?Boolean

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

Returns:

  • (Boolean)

See Also:

  • SXP::Pair.https:/srfihttps:/srfi.schemershttps:/srfi.schemers.org/srfi-1/srfi-1https:/srfi.schemers.org/srfi-1/srfi-1.htmlhttps:/srfi.schemers.org/srfi-1/srfi-1.html#ImproperLists


31
32
33
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/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.

Returns:

  • (Boolean)


22
23
24
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/pair.rb', line 22

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

#inspectString

Returns a developer-friendly representation of this pair.

Returns:



56
57
58
59
60
61
62
63
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/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.

Returns:

  • (Boolean)

See Also:

  • SXP::Pair.https:/srfihttps:/srfi.schemershttps:/srfi.schemers.org/srfi-1/srfi-1https:/srfi.schemers.org/srfi-1/srfi-1.htmlhttps:/srfi.schemers.org/srfi-1/srfi-1.html#ImproperLists


40
41
42
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/pair.rb', line 40

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

#to_aArray

Returns an array representation of this pair.

Returns:



48
49
50
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sxp.rb-7a771a32c5fe/lib/sxp/pair.rb', line 48

def to_a
  [head, tail]
end