
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Lightweight money and currency handler for working with financial calculations. Ensures precision without sacrificing speed. Eschews complexity by only providing what you need to get your job done.
require 'cashrb'
# Works with cents to avoid Floating point errors
n = Cash.new(100)
n.cents #=> 100
n.to_s #=> "1.00"
n.to_f #=> 1.0
# Don't like passing cents, set :from => :decimal and use a decimal value
n = Cash.new(1.11, from: :decimal)
n.cents #=> 111
n.to_s #=> "1.11"
n.to_f #=> 1.11
# Hate cents and always want to pass a decimal, just set the default
Cash.default_from = :decimal
n = Cash.new(1.11)
n.cents #=> 111
# Define currency as you see fit.
a = Cash.new(100, currency: :usd)
b = Cash.new(100, currency: :eur)
a + b #=> Error! Cash::IncompatibleCurrency
# Default is 100 cents in a dollar. Is your currency different, then just
# tell it.
n = Cash.new(100, cents_in_dollar: 5)
n.cents #=> 100
n.to_s #=> "20.0"
n.to_f #=> 20.0
n = Cash.new(100, cents_in_dollar: 10)
n.cents #=> 100
n.to_s #=> "10.0"
n.to_f #=> 10.0
n = Cash.new(100, cents_in_dollar: 1)
n.cents #=> 100
n.to_s #=> "100"
n.to_f #=> 100.0
# The default rounding method when dealing with fractional cents is
# BigDecimal::ROUND_HALF_UP. Would you rather use bankers rounding; just
# pass it as an argument.
n = Cash.new(2.5)
n.cents #=> 3
n = Cash.new(2.5, rounding_method: BigDecimal::ROUND_HALF_EVEN)
n.cents #=> 2
# Sick of specifying :cents_in_whole, :rounding_method and :currency; just
# set their defaults.
Cash.default_cents_in_whole = 10
Cash.default_rounding_method = BigDecimal::ROUND_DOWN
Cash.default_currency = :EUR
n = Cash.new(100)
n.to_s #=> "10.0"
n.to_f #=> 10.0
n.currency #=> :EUR
n = Cash.new(1.9)
n.cents #=> 1
# If your currency object implements :cents_in_whole, we'll go ahead and
# use that.
module MyCurrency
def self.cents_in_whole
10
end
end
n = Cash.new(9, :currency => MyCurrency)
n.to_f #=> 0.9
FAQs
Unknown package
We found that cashrb 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
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.