Class: Nockr::Cell

Inherits:
Noun
  • Object
show all
Defined in:
lib/nockr/cell.rb

Instance Attribute Summary collapse

Attributes inherited from Noun

#n

Instance Method Summary collapse

Methods inherited from Noun

#nonify, #to_tuples

Constructor Details

#initialize(head:, tail:) ⇒ Cell

Returns a new instance of Cell.



7
8
9
10
# File 'lib/nockr/cell.rb', line 7

def initialize(head:, tail:)
  @h = head
  @t = tail
end

Instance Attribute Details

#hObject (readonly)

Returns the value of attribute h.



5
6
7
# File 'lib/nockr/cell.rb', line 5

def h
  @h
end

#tObject (readonly)

Returns the value of attribute t.



5
6
7
# File 'lib/nockr/cell.rb', line 5

def t
  @t
end

Instance Method Details

#==(another_cell) ⇒ Object



12
13
14
# File 'lib/nockr/cell.rb', line 12

def ==(another_cell)
  another_cell.h == self.h && another_cell.t == self.t
end

#aryObject



16
17
18
# File 'lib/nockr/cell.rb', line 16

def ary
  [@h.cell? ? @h.ary : @h.i, @t.cell? ? @t.ary : @t.i]
end

#at(index:) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
# File 'lib/nockr/cell.rb', line 20

def at(index:)
  raise ArgumentError.new("Invalid Index.") if index < 1 || index > 3
  return self if 1 == index
  return @h if 2 == index
  return @t if 3 == index
end

#atom?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/nockr/cell.rb', line 27

def atom?
  false
end

#cell?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/nockr/cell.rb', line 31

def cell?
  true
end