Class: Cards::Card

Inherits:
Object show all
Defined in:
lib/cards/card.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Card

Returns a new instance of Card.



6
7
8
9
10
# File 'lib/cards/card.rb', line 6

def initialize(name)
  @name = name
  @x, @y = 0, 0
  @children = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/cards/card.rb', line 3

def children
  @children
end

#colorObject

Returns the value of attribute color.



3
4
5
# File 'lib/cards/card.rb', line 3

def color
  @color
end

#layoutObject



21
22
23
# File 'lib/cards/card.rb', line 21

def layout
  my_layout.layout(self)
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/cards/card.rb', line 3

def name
  @name
end

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/cards/card.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/cards/card.rb', line 3

def y
  @y
end

Instance Method Details

#add(*cards) ⇒ Object



12
13
14
# File 'lib/cards/card.rb', line 12

def add(*cards)
  @children += cards
end

#cellObject



35
# File 'lib/cards/card.rb', line 35

def cell() [x, y]; end

#cell=(cells) ⇒ Object



36
# File 'lib/cards/card.rb', line 36

def cell=(cells) self.x, self.y = *cells; end

#heightObject



30
31
32
33
# File 'lib/cards/card.rb', line 30

def height
  return 1 if children.empty?
  my_layout.height(self)
end

#visit {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Cards::Card)

    the object that the method was called on



16
17
18
19
# File 'lib/cards/card.rb', line 16

def visit(&block)
  yield self
  @children.each {|c| c.visit(&block) }
end

#widthObject



25
26
27
28
# File 'lib/cards/card.rb', line 25

def width
  return 1 if children.empty?
  my_layout.width(self)
end