boop

Object-oriented programming for bash 4.3+ — real classes, objects, inheritance, and a standard library, in pure bash.


Project maintained by ydbxmhc Hosted on GitHub Pages

Cube

A cube — all faces equal. Inherits from Box, overrides face and volume methods to use the single size dimension.

Dependencies

. boop Cube    # automatically loads Box

Constructor

into=c Cube size=4

The constructor sets length, width, and height equal to size in the underlying Box descriptor. size is required and must be a positive integer; omitting it returns non-zero with an error.

Properties

Property Type Description
size integer Edge length (all faces equal)
length integer Inherited from Box (set = size)
width integer Inherited from Box (set = size)
height integer Inherited from Box (set = size)
unit string Optional unit label

Methods

All geometry methods are overridden to use size directly:

into=v $c.volume           # size³
into=a $c.side             # size²
into=a $c.top              # size² (delegates to side)
into=a $c.end              # size² (delegates to side)
into=a $c.bottom           # size² (delegates to side)

Typecasting

Cube inherits from Box, so you can call Box methods via typecast:

_Class=Box $c.volume        # dispatches to Box.volume

Example

. boop Cube

into=c Cube size=5
into=v $c.volume
printf "Volume: %s\n" "$v"   # Volume: 125

$c.isa Box && printf "yes\n"   # yes — Cube inherits from Box

↑ Site map