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

Box

A 3D rectangular prism with named dimensions. Demonstrates basic class definition, method registration, and inheritance in boop.

Dependencies

. boop Box

Constructor

into=b Box length=5 width=3 height=7
into=b Box length=5 width=3 height=7 unit=cm color=red

All dimensions are integers. unit and color are optional metadata properties stored in the descriptor but not used by any built-in method.

Properties

Property Type Description
length integer Length of the box
width integer Width of the box
height integer Height of the box
unit string Optional unit label (e.g. “cm”)
color string Optional color label

Methods

Geometry

into=v $b.volume          # length × width × height
into=a $b.top             # length × width (top face)
into=a $b.bottom          # same as top
into=a $b.side            # height × length
into=a $b.end             # height × width

Utility

into=a $b.area 4 5        # generic 2D multiply (two args)
into=c $b.calc 2 3 4      # generic N-way multiply

calc accepts variadic integer arguments and returns their product. The required=N typecast enforces exact argument count:

required=2 into=a $b.area 4 5    # must be exactly 2 args

Inherited (from boop)

into=v $b.get "length"    # read property
$b.set "color" "blue"     # write property
$b.isa Box && printf "yes\n"    # type check (walks inheritance)
into=s $b.toString         # Box(_id){ length=5 width=3 height=7 }

Example

. boop Box

into=b Box length=10 width=5 height=3
into=v $b.volume
printf "Volume: %s\n" "$v"   # Volume: 150

into=t $b.top
printf "Top area: %s\n" "$t" # Top area: 50

↑ Site map