Functions
Sumi::F is the supported toolbox shared by Sumi components and advanced extensions. Use it before reimplementing
Sumi-specific numeric, discovery, command, naming, or status behavior. It is deliberately smaller than a
general-purpose utility library.
| Need | Start with | Result or policy |
|---|---|---|
| Degree-based trigonometry and approximate comparison | sin, cos, eq?, approx, with_precision | Function::Math.precision is thread-local |
Find a .sumi file while walking upward | locate or configurable Function::Locate | immutable Function::Location |
| Compare or write generated files | changed?, out, touch | path or change status |
| Run an argv-safe child process | sh or success-requiring sh! | immutable Function::Shell::Result |
| Build Sumi-facing names | demodulize, pluralize | string |
| Report build progress | do, mayok, ok, notok, ui | status on standard error |
In ordinary library code, spell the facade as Sumi::F. Bare F is available to .sumi scripts. It is also
available to receivers that include the top-level DSL. require "sumi/function" does not install a global F.
Numeric work
Angles are in degrees. Precision belongs to the current thread. Use with_precision for a temporary policy. Pass
precision: for one comparison.
Sumi::F.with_precision(3) do
Sumi::F.cos(60)
Sumi::F.approx(1.0 / 3)
endCommands
sh receives argv entries, not a shell command string. It captures both streams and returns a result after an
unsuccessful exit. Use sh! to raise Sumi::Error after an unsuccessful exit.
require "rbconfig"
result = Sumi::F.sh(RbConfig.ruby, "-e", 'warn "invalid"; exit 3')
raise unless result.notok?
raise unless result.exit_code == 3
raise unless result.err == "invalid"File discovery
locate qualifies an extensionless name as .sumi and searches from the given directory toward the filesystem root.
The returned location records both the matching file and the directory that supplied it.
require "fileutils"
FileUtils.mkdir_p("project/drawings")
File.write("project/palette.sumi", "COLORS = %w[black white]\n")
location = Sumi::F.locate("palette", "project/drawings")
raise unless location.slug == "palette.sumi"
raise unless location.dir == File.expand_path("project")
Use Function::Locate directly to search without adding the .sumi extension. It also supports several candidates,
exclusions, and a custom matcher. The API reference documents facade
methods, return values, and failure contracts.