
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
records gem / library - frozen / immutable structs with copy on updates
Use Record.new
like Struct.new
to build / create a new frozen / immutable
record class. Example:
Record.new( :Account,
balance: Integer,
allowances: Hash )
# -or-
Record.new :Account,
balance: Integer,
allowances: Hash
# -or-
Record.new :Account, { balance: Integer,
allowances: Hash }
# -or-
class Account < Record::Base
field :balance, Integer
field :allowances, Hash
end
And use the new record class like:
account1a = Account.new( 1, {} )
account1a.frozen? #=> true
account1a.values.frozen? #=> true
account1a.balance #=> 1
account1a.allowances #=> {}
account1a.values #=> [1, {}]
Account.keys #=> [:balance, :allowances]
Account.fields #=> [<Field @key=:balance, @index=0, @type=Integer>,
# <Field @key=:allowances, @index=1, @type=Hash>]
Account.index( :balance ) #=> 0
Account.index( :allowances ) #=> 1
Note: The update
method (or the <<
alias)
ALWAYS returns a new record.
account1a.update( balance: 20 ) #=> [20, {}]
account1a.update( balance: 30 ) #=> [30, {}]
account1a.update( { balance: 30 } ) #=> [30, {}]
account1a << { balance: 20 } #=> [20, {}]
account1a << { balance: 30 } #=> [30, {}]
account1b = account1a.update( balance: 40, allowances: { 'Alice': 20 } )
account1b.balance #=> 40
account1b.allowances #=> { 'Alice': 20 }
account1b.values #=> [40, { 'Alice': 20 } ]
# ...
And so on and so forth.
{...}
and ={...}
Using the Record Update Pragma. Lets you
account1a {... balance: 20 } #=> [20, {}]
account1a {... balance: 30 } #=> [30, {}]
account1a = {... balance: 40, allowances: { 'Alice': 20 }}
turn into:
account1a.update( balance: 20 ) #=> [20, {}]
account1a.update( balance: 30 ) #=> [30, {}]
account1a = account1a.update( balance: 40, allowances: { 'Alice': 20 } )
See Language Syntax Pragmas - Let's Evolve Ruby by Experimenting in a Pragma(tic) Way for more.
The records
scripts are dedicated to the public domain.
Use it as you please with no restrictions whatsoever.
Send them along to the wwwmake forum. Thanks!
FAQs
Unknown package
We found that records demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.