Skip to content

Add margin's :flush option, Paramix and String::Mask - #347

Merged
trans merged 5 commits into
mainfrom
feature/margin-flush-paramix-mask
Nov 18, 2026
Merged

trans merged 5 commits into
mainfrom
feature/margin-flush-paramix-mask

Conversation

@trans

@trans trans commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Three additions for 4.2.0, found while going through the other Rubyworks projects. One commit each.

String#margin takes :flush

"abc\n    xyz".margin(2)               #=> "  abc\n      xyz"
"abc\n    xyz".margin(2, flush: true)  #=> "  abc\n  xyz"

Every line that isn't blank gets the same margin. This is what String#tab did before it was removed in 3.1.0 (tapout, turn and dnote still carry copies), except that blank lines are left alone and leading tabs count as indentation. String#tabto is not restored: it is margin(n, lead: true).

margin had one test; it now has ten.

Paramix::Parametric (standard, require 'facets/paramix')

Parametric mixins: include Greeter[:name => 'x']. Part of Facets until 2.7.0, then the Paramix gem; this is the gem's code, with tests taken from its demos. One change: in the mixin, public, private and protected still define a method when given a block, and now also take names alone as Module's own do.

String::Mask and String#mask (core, opt-in, require 'facets/string/mask')

Facets' string/mask until 2.7.0, then the Strmask gem. Not loaded by require 'facets'; listed as # uncommon in facets/string.rb. Changed from the gem:

  • Masks of different lengths combine. The gem raised a TypeError when the second was shorter, and cut the result short when the first was.
  • A mask can be made without an empty-slot character. The gem's to_s raised for one.
  • hash and eql? are defined, so equal masks are the same hash key.
  • apply works. It called String#to_mask and Functor, which the gem didn't define.
  • Only methods a string has are passed on to it, and respond_to? agrees.
  • It works under frozen string literals.
  • A mask is equal only to another mask; compare mask.to_s with a string. The gem compared a string with the mask's internal form.

Checks

rake test (1510 tests, with the same 4 pending as on main) and rake qed:code pass on Ruby 3.4.9.

🤖 Generated with Claude Code

trans and others added 5 commits November 17, 2026 15:38
With :flush, every line that isn't blank gets the same margin, and
relative indentation isn't kept. This is what String#tab did before it
was removed in 3.1.0, except that blank lines are left alone and leading
tabs count as indentation. tapout, turn and dnote each carry a copy of
tab.

Fill out margin's tests, which had one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Paramix::Parametric makes a module take parameters where it is included
or extended: include M[:name => 'x']. It was part of Facets until 2.7.0,
when it became the Paramix gem; this is that gem's version, with tests
from its demos.

In the mixin, public, private and protected still define a method when
given a block, and now also take names alone, as Module's own do.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mask is a string in which some characters are empty slots; masks
combine character by character with +, -, *, & and ^. It was Facets'
string/mask until 2.7.0, when it became the Strmask gem. It is loaded
with require 'facets/string/mask', not by require 'facets'.

Changed from the gem:

- Masks of different lengths combine, the shorter one's missing
  characters counting as empty. The gem raised a TypeError when the
  second was shorter, and cut the result short when the first was.
- A mask can be made without an empty-slot character; the gem's to_s
  and inspect raised for one.
- hash and eql? are defined, so equal masks are the same hash key.
- apply works: it called String#to_mask and Functor, neither of which
  the gem defined.
- Only methods a string has are passed on to it, and respond_to?
  agrees. The gem rescued NoMethodError around the call, which hid
  errors raised inside the method.
- It works under frozen string literals.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A mask compared equal to an ordinary string read as a mask, so it was
equal to both its printed and its internal form, which aren't equal to
each other, and == disagreed with eql?. Compare mask.to_s with a string
instead.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@trans
trans merged commit a4c6b7d into main Nov 18, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant