minting 1.9.6 → 1.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -25
- data/Rakefile +16 -20
- data/bin/bench_check +2 -2
- data/doc/Mint/Currency.html +183 -94
- data/doc/Mint/Money.html +866 -334
- data/doc/Mint/RangeStepPatch.html +1 -1
- data/doc/Mint/Registry.html +10 -10
- data/doc/Mint/Rounding.html +2 -2
- data/doc/Mint/UnknownCurrency.html +6 -4
- data/doc/Mint.html +33 -106
- data/doc/Minting.html +2 -2
- data/doc/Numeric.html +479 -0
- data/doc/String.html +241 -0
- data/doc/_index.html +27 -1
- data/doc/agents/copilot-instructions.md +3 -3
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +47 -33
- data/doc/index.html +47 -33
- data/doc/method_list.html +125 -53
- data/doc/top-level-namespace.html +5 -21
- data/lib/minting/currency/currency.rb +6 -3
- data/lib/minting/data/world-currencies.yaml +75 -23
- data/lib/minting/mint/i18n.rb +1 -1
- data/lib/minting/mint/rounding.rb +1 -0
- data/lib/minting/money/conversion.rb +1 -0
- data/lib/minting/money/format/formatting.rb +88 -55
- data/lib/minting/money/format/to_s.rb +20 -3
- data/lib/minting/money/money.rb +0 -4
- data/lib/minting/version.rb +1 -1
- metadata +3 -2
- data/doc/Mint/CurrencyRegistry.html +0 -511
data/doc/String.html
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
Class: String
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.9.44
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css">
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css">
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "String";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div id="main_progress" aria-hidden="true"></div>
|
|
31
|
+
|
|
32
|
+
<div class="nav_wrap">
|
|
33
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
|
34
|
+
<div id="resizer"></div>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div id="main" tabindex="-1">
|
|
38
|
+
<div id="header">
|
|
39
|
+
<div id="menu">
|
|
40
|
+
|
|
41
|
+
<a href="_index.html">Index (S)</a> »
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
<span class="title">String</span>
|
|
45
|
+
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div id="search">
|
|
49
|
+
|
|
50
|
+
<a class="full_list_link" id="class_list_link"
|
|
51
|
+
href="class_list.html">
|
|
52
|
+
|
|
53
|
+
<svg width="24" height="24">
|
|
54
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
55
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
56
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
57
|
+
</svg>
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
<div class="clear"></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div id="content"><h1>Class: String
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
</h1>
|
|
69
|
+
<div class="box_info">
|
|
70
|
+
|
|
71
|
+
<dl>
|
|
72
|
+
<dt>Inherits:</dt>
|
|
73
|
+
<dd>
|
|
74
|
+
<span class="inheritName">Object</span>
|
|
75
|
+
|
|
76
|
+
<ul class="fullTree">
|
|
77
|
+
<li>Object</li>
|
|
78
|
+
|
|
79
|
+
<li class="next">String</li>
|
|
80
|
+
|
|
81
|
+
</ul>
|
|
82
|
+
<a href="#" class="inheritanceTree">show all</a>
|
|
83
|
+
|
|
84
|
+
</dd>
|
|
85
|
+
</dl>
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
<dl>
|
|
98
|
+
<dt>Defined in:</dt>
|
|
99
|
+
<dd>lib/minting/mint/dsl/string.rb
|
|
100
|
+
</dd>
|
|
101
|
+
</dl>
|
|
102
|
+
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<h2>Overview</h2><div class="docstring">
|
|
106
|
+
<div class="discussion">
|
|
107
|
+
<p>Core extension: adds money-parsing helper to String.</p>
|
|
108
|
+
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
<div class="tags">
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
<h2>
|
|
123
|
+
Instance Method Summary
|
|
124
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
125
|
+
</h2>
|
|
126
|
+
|
|
127
|
+
<ul class="summary">
|
|
128
|
+
|
|
129
|
+
<li class="public ">
|
|
130
|
+
<span class="summary_signature">
|
|
131
|
+
|
|
132
|
+
<a href="#to_money-instance_method" title="#to_money (instance method)">#<strong>to_money</strong>(currency = nil) ⇒ Money </a>
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
</span>
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
<span class="summary_desc"><div class='inline'><p>Parses self as a numeric string and creates a Money in the given currency.</p></div></span>
|
|
147
|
+
|
|
148
|
+
</li>
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
</ul>
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
<div id="instance_method_details" class="method_details_list">
|
|
158
|
+
<h2>Instance Method Details</h2>
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
<div class="method_details first">
|
|
162
|
+
<h3 class="signature first" id="to_money-instance_method">
|
|
163
|
+
|
|
164
|
+
#<strong>to_money</strong>(currency = nil) ⇒ <tt><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></tt>
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
</h3><div class="docstring">
|
|
171
|
+
<div class="discussion">
|
|
172
|
+
<p>Parses self as a numeric string and creates a Money in the given currency.</p>
|
|
173
|
+
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
<div class="tags">
|
|
177
|
+
<p class="tag_title">Parameters:</p>
|
|
178
|
+
<ul class="param">
|
|
179
|
+
|
|
180
|
+
<li>
|
|
181
|
+
|
|
182
|
+
<span class='name'>currency</span>
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
<span class='type'>(<tt><span class='object_link'><a href="" title="String (class)">String</a></span></tt>, <tt>Symbol</tt>, <tt><span class='object_link'><a href="top-level-namespace.html#Currency-constant" title="Currency (constant)">Currency</a></span></tt>)</span>
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
—
|
|
192
|
+
<div class='inline'><p>target currency</p></div>
|
|
193
|
+
|
|
194
|
+
</li>
|
|
195
|
+
|
|
196
|
+
</ul>
|
|
197
|
+
|
|
198
|
+
<p class="tag_title">Returns:</p>
|
|
199
|
+
<ul class="return">
|
|
200
|
+
|
|
201
|
+
<li>
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
<span class='type'>(<tt><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></tt>)</span>
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
</li>
|
|
209
|
+
|
|
210
|
+
</ul>
|
|
211
|
+
|
|
212
|
+
</div><table class="source_code">
|
|
213
|
+
<tr>
|
|
214
|
+
<td>
|
|
215
|
+
<pre class="lines">
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
9</pre>
|
|
219
|
+
</td>
|
|
220
|
+
<td>
|
|
221
|
+
<pre class="code"><span class="info file"># File 'lib/minting/mint/dsl/string.rb', line 9</span>
|
|
222
|
+
|
|
223
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_to_money'>to_money</span><span class='lparen'>(</span><span class='id identifier rubyid_currency'>currency</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse'><span class='object_link'><a href="Mint/Money.html#parse-class_method" title="Mint::Money.parse (method)">parse</a></span></span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_currency'>currency</span><span class='rparen'>)</span></pre>
|
|
224
|
+
</td>
|
|
225
|
+
</tr>
|
|
226
|
+
</table>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
<div id="footer">
|
|
234
|
+
Generated on Wed Jul 1 01:11:53 2026 by
|
|
235
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
236
|
+
0.9.44 (ruby-4.0.5).
|
|
237
|
+
</div>
|
|
238
|
+
|
|
239
|
+
</div>
|
|
240
|
+
</body>
|
|
241
|
+
</html>
|
data/doc/_index.html
CHANGED
|
@@ -118,6 +118,19 @@
|
|
|
118
118
|
</ul>
|
|
119
119
|
|
|
120
120
|
|
|
121
|
+
<ul id="alpha_N" class="alpha">
|
|
122
|
+
<li class="letter">N</li>
|
|
123
|
+
<ul>
|
|
124
|
+
|
|
125
|
+
<li>
|
|
126
|
+
<span class='object_link'><a href="Numeric.html" title="Numeric (class)">Numeric</a></span>
|
|
127
|
+
|
|
128
|
+
</li>
|
|
129
|
+
|
|
130
|
+
</ul>
|
|
131
|
+
</ul>
|
|
132
|
+
|
|
133
|
+
|
|
121
134
|
<ul id="alpha_R" class="alpha">
|
|
122
135
|
<li class="letter">R</li>
|
|
123
136
|
<ul>
|
|
@@ -147,6 +160,19 @@
|
|
|
147
160
|
</ul>
|
|
148
161
|
|
|
149
162
|
|
|
163
|
+
<ul id="alpha_S" class="alpha">
|
|
164
|
+
<li class="letter">S</li>
|
|
165
|
+
<ul>
|
|
166
|
+
|
|
167
|
+
<li>
|
|
168
|
+
<span class='object_link'><a href="String.html" title="String (class)">String</a></span>
|
|
169
|
+
|
|
170
|
+
</li>
|
|
171
|
+
|
|
172
|
+
</ul>
|
|
173
|
+
</ul>
|
|
174
|
+
|
|
175
|
+
|
|
150
176
|
<ul id="alpha_U" class="alpha">
|
|
151
177
|
<li class="letter">U</li>
|
|
152
178
|
<ul>
|
|
@@ -170,7 +196,7 @@
|
|
|
170
196
|
</div>
|
|
171
197
|
|
|
172
198
|
<div id="footer">
|
|
173
|
-
Generated on
|
|
199
|
+
Generated on Wed Jul 1 01:11:52 2026 by
|
|
174
200
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
175
201
|
0.9.44 (ruby-4.0.5).
|
|
176
202
|
</div>
|
|
@@ -4,7 +4,7 @@ Repository overview
|
|
|
4
4
|
- Location of main code: lib/minting and its subfolders (mint/, money/)
|
|
5
5
|
- Public API surface: Mint (factory/helpers), Mint::Money, Mint::Currency
|
|
6
6
|
- Data: built-in currencies in lib/minting/data/currencies.yaml
|
|
7
|
-
- Tests: Minitest (unit) + performance benchmarks under
|
|
7
|
+
- Tests: Minitest (unit) + performance benchmarks under bench/
|
|
8
8
|
|
|
9
9
|
Build, test and lint commands
|
|
10
10
|
|
|
@@ -43,7 +43,7 @@ High-level architecture (big picture)
|
|
|
43
43
|
- Currency: lightweight value object (code, subunit, symbol, priority, minimum_amount).
|
|
44
44
|
- Money: immutable value object stored as Rational and rounded to currency.subunit. Core concerns split across lib/minting/money/* (arithmetics, formatting, conversion, coercion, allocation, parsing, comparable).
|
|
45
45
|
- Refinements: Numeric/String/Refinements in lib/minting/mint/refinements.rb expose helpers like 10.dollars, 4.to_money('USD'), and require `using Mint` in scope.
|
|
46
|
-
- Performance tests: separate bench tasks under Rake;
|
|
46
|
+
- Performance tests: separate bench tasks under Rake; bench/ holds benchmark suites.
|
|
47
47
|
|
|
48
48
|
Key conventions and repo-specific rules
|
|
49
49
|
|
|
@@ -59,7 +59,7 @@ Files and places to check first during edits
|
|
|
59
59
|
- lib/minting/money - core behavior and arithmetic
|
|
60
60
|
- lib/minting/mint - currency registry, refinements, and factory API
|
|
61
61
|
- lib/minting/data/currencies.yaml - canonical currency definitions
|
|
62
|
-
- test/ - unit tests;
|
|
62
|
+
- test/ - unit tests; bench/ - benchmark suites
|
|
63
63
|
|
|
64
64
|
Notes for Copilot sessions
|
|
65
65
|
|
data/doc/class_list.html
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
|
|
47
47
|
<ul id="full_list" class="class">
|
|
48
48
|
<li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li>
|
|
49
|
-
<li id='object_Mint' class='even'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='Mint child nodes' aria-expanded='false' aria-controls='object_Mint'></a> <span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_Mint'><ul><li id='object_Mint::Currency' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span> < Data<small class='search_info'>Mint</small></div></li><li id='object_Mint::Money' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> < Object<small class='search_info'>Mint</small></div></li><li id='object_Mint::RangeStepPatch' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/RangeStepPatch.html" title="Mint::RangeStepPatch (module)">RangeStepPatch</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::Registry' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Registry.html" title="Mint::Registry (module)">Registry</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::Rounding' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Rounding.html" title="Mint::Rounding (module)">Rounding</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::UnknownCurrency' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/UnknownCurrency.html" title="Mint::UnknownCurrency (class)">UnknownCurrency</a></span> <
|
|
49
|
+
<li id='object_Mint' class='even'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='Mint child nodes' aria-expanded='false' aria-controls='object_Mint'></a> <span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_Mint'><ul><li id='object_Mint::Currency' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Currency.html" title="Mint::Currency (class)">Currency</a></span> < Data<small class='search_info'>Mint</small></div></li><li id='object_Mint::Money' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Money.html" title="Mint::Money (class)">Money</a></span> < Object<small class='search_info'>Mint</small></div></li><li id='object_Mint::RangeStepPatch' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/RangeStepPatch.html" title="Mint::RangeStepPatch (module)">RangeStepPatch</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::Registry' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Registry.html" title="Mint::Registry (module)">Registry</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::Rounding' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/Rounding.html" title="Mint::Rounding (module)">Rounding</a></span><small class='search_info'>Mint</small></div></li><li id='object_Mint::UnknownCurrency' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="Mint/UnknownCurrency.html" title="Mint::UnknownCurrency (class)">UnknownCurrency</a></span> < ArgumentError<small class='search_info'>Mint</small></div></li></ul></div></li><li id='object_Minting' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Minting.html" title="Minting (module)">Minting</a></span><small class='search_info'>Top Level Namespace</small></div></li><li id='object_Numeric' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Numeric.html" title="Numeric (class)">Numeric</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li><li id='object_String' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="String.html" title="String (class)">String</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li>
|
|
50
50
|
|
|
51
51
|
</ul>
|
|
52
52
|
</div>
|
data/doc/file.README.html
CHANGED
|
@@ -78,11 +78,11 @@
|
|
|
78
78
|
<h3 id="Exact_precision">Exact precision</h3>
|
|
79
79
|
<p>Amounts are stored as <code>Rational</code> and rounded to the currency subunit. No floating-point surprises, ever.</p>
|
|
80
80
|
<h3 id="Blazing_performance">Blazing performance</h3>
|
|
81
|
-
<p>Minting is faster than the Money gem for everyday operations and <strong>over 10× faster for formatting</strong>. See full benchmarks in the <a href="test/performance/
|
|
81
|
+
<p>Minting is faster than the Money gem for everyday operations and <strong>over 10× faster for formatting</strong>. See full benchmarks in the <a href="test/performance/BENCHMARKS.md">Performance Guide</a>.</p>
|
|
82
82
|
<h3 id="Clean__modern_API">Clean, modern API</h3>
|
|
83
83
|
<p>Intuitive interface, descriptive error messages, and sensible defaults. Works the way you expect.</p>
|
|
84
84
|
<h3 id="Rails_ready">Rails-ready</h3>
|
|
85
|
-
<p>Use with the <a href="https://github.com/gferraz/
|
|
85
|
+
<p>Use with the <a href="https://github.com/gferraz/attribute-money">attribute-money</a> companion gem for drop-in ActiveRecord type casting, validators, and form helpers.</p>
|
|
86
86
|
<h3 id="Quality_code">Quality code</h3>
|
|
87
87
|
<ul>
|
|
88
88
|
<li><strong>100% test coverage</strong> — every line exercised</li>
|
|
@@ -101,9 +101,6 @@
|
|
|
101
101
|
<span class='comment'># Create money
|
|
102
102
|
</span><span class='id identifier rubyid_ten'>ten</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='int'>10</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 10.00]
|
|
103
103
|
</span>
|
|
104
|
-
<span class='comment'># Create money using Numeric refinements
|
|
105
|
-
</span><span class='id identifier rubyid_using'>using</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span>
|
|
106
|
-
|
|
107
104
|
<span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_dollar'>dollar</span> <span class='op'>==</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='int'>1</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> true
|
|
108
105
|
</span><span class='id identifier rubyid_ten'>ten</span> <span class='op'>=</span> <span class='int'>10</span><span class='period'>.</span><span class='id identifier rubyid_dollars'>dollars</span> <span class='comment'>#=> [USD 10.00]
|
|
109
106
|
</span><span class='int'>4</span><span class='period'>.</span><span class='id identifier rubyid_to_money'>to_money</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> [USD 4.00]
|
|
@@ -124,34 +121,51 @@
|
|
|
124
121
|
</span>
|
|
125
122
|
<span class='comment'># Format (uses Kernel.format syntax)
|
|
126
123
|
</span><span class='id identifier rubyid_price'>price</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>9.99</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
124
|
+
<span class='id identifier rubyid_loss'>loss</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='op'>-</span><span class='float'>1234.56</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
127
125
|
|
|
128
|
-
<span class='
|
|
129
|
-
</span><span class='id identifier
|
|
130
|
-
</span><span class='
|
|
131
|
-
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier
|
|
132
|
-
</span><span class='
|
|
126
|
+
<span class='comment'># Built-in named presets
|
|
127
|
+
</span><span class='id identifier rubyid_loss'>loss</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='symbol'>:accounting</span><span class='rparen'>)</span> <span class='comment'>#=> "($1,234.56)"
|
|
128
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>1234.56</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>EUR</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='symbol'>:european</span><span class='rparen'>)</span> <span class='comment'>#=> "1.234,56 €"
|
|
129
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='symbol'>:amount</span><span class='rparen'>)</span> <span class='comment'>#=> "9.99"
|
|
130
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='symbol'>:currency</span><span class='rparen'>)</span> <span class='comment'>#=> "USD 9.99"
|
|
131
|
+
</span>
|
|
132
|
+
<span class='comment'># Presets can be overridden with explicit kwargs
|
|
133
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>1234.56</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>EUR</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='symbol'>:european</span><span class='comma'>,</span> <span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<amount>f %<currency>s</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
134
|
+
<span class='comment'>#=> "1.234,56 EUR"
|
|
135
|
+
</span>
|
|
136
|
+
<span class='comment'># Or use direct format strings
|
|
137
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span> <span class='comment'>#=> "$9.99",
|
|
138
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<amount>d</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "9",
|
|
139
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<symbol>s%<amount>f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "$9.99",
|
|
140
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<symbol>s%<amount>+f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "$+9.99",
|
|
141
|
+
</span><span class='lparen'>(</span><span class='op'>-</span><span class='id identifier rubyid_price'>price</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<amount>f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "-9.99",
|
|
133
142
|
</span>
|
|
134
143
|
<span class='comment'># Format with padding
|
|
135
144
|
</span><span class='id identifier rubyid_price_in_euros'>price_in_euros</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>12.34</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>EUR</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
136
145
|
|
|
137
|
-
<span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier
|
|
138
|
-
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier
|
|
139
|
-
</span><span class='lparen'>(</span><span class='op'>-</span><span class='id identifier rubyid_price'>price</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier
|
|
146
|
+
<span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>--%<amount>7d</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "-- 9"
|
|
147
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> %<amount>10f %<currency>s</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> " 9.99 USD"
|
|
148
|
+
</span><span class='lparen'>(</span><span class='op'>-</span><span class='id identifier rubyid_price'>price</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> %<amount>10f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> " -9.99"
|
|
140
149
|
</span>
|
|
141
|
-
<span class='id identifier rubyid_price_in_euros'>price_in_euros</span><span class='period'>.</span><span class='id identifier
|
|
150
|
+
<span class='id identifier rubyid_price_in_euros'>price_in_euros</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<symbol>2s%<amount>+10f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> " € +12.34"
|
|
142
151
|
</span>
|
|
143
152
|
<span class='comment'># Integral & fractional parts
|
|
144
|
-
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier
|
|
145
|
-
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>0.99</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier
|
|
153
|
+
</span><span class='id identifier rubyid_price'>price</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<integral>d %<fractional>d/100</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "9 99/100"
|
|
154
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>0.99</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<integral>d dollars and %<fractional>02d cents</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
146
155
|
<span class='comment'>#=> "0 dollars and 99 cents"
|
|
147
156
|
</span>
|
|
148
157
|
<span class='comment'># Per-sign Hash format (e.g. accounting parentheses for losses)
|
|
149
158
|
</span><span class='id identifier rubyid_loss'>loss</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='op'>-</span><span class='float'>1234.56</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
150
|
-
<span class='id identifier rubyid_loss'>loss</span><span class='period'>.</span><span class='id identifier
|
|
151
|
-
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='int'>0</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BRL</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier
|
|
159
|
+
<span class='id identifier rubyid_loss'>loss</span><span class='period'>.</span><span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='label'>format:</span> <span class='lbrace'>{</span> <span class='label'>negative:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>(%<symbol>s%<amount>f)</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span> <span class='comment'>#=> "($1,234.56)"
|
|
160
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='int'>0</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>BRL</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='label'>format:</span> <span class='lbrace'>{</span> <span class='label'>zero:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>--</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span> <span class='comment'>#=> "--"
|
|
152
161
|
</span><span class='comment'># All three keys at once:
|
|
153
162
|
</span><span class='id identifier rubyid_fmt'>fmt</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='label'>positive:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<symbol>s%<amount>f</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>negative:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>(%<symbol>s%<amount>f)</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='label'>zero:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>--</span><span class='tstring_end'>'</span></span> <span class='rbrace'>}</span>
|
|
154
|
-
<span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>1234.56</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier
|
|
163
|
+
<span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='float'>1234.56</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='label'>format:</span> <span class='id identifier rubyid_fmt'>fmt</span><span class='rparen'>)</span> <span class='comment'>#=> "$1,234.56"
|
|
164
|
+
</span>
|
|
165
|
+
<span class='comment'># Disambiguated symbol (e.g. "US$" vs "C$" vs "A$")
|
|
166
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='int'>10</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>USD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<dsymbol>s%<amount>f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "US$10.00"
|
|
167
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='int'>10</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>CAD</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<dsymbol>s%<amount>f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "C$10.00"
|
|
168
|
+
</span><span class='const'><span class='object_link'><a href="Mint.html" title="Mint (module)">Mint</a></span></span><span class='period'>.</span><span class='id identifier rubyid_money'><span class='object_link'><a href="Mint.html#money-class_method" title="Mint.money (method)">money</a></span></span><span class='lparen'>(</span><span class='int'>10</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>EUR</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_format'><span class='object_link'><a href="Mint/Money.html#format-instance_method" title="Mint::Money#format (method)">format</a></span></span><span class='lparen'>(</span><span class='label'>format:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>%<dsymbol>s%<amount>f</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'>#=> "€10.00" (no dsymbol, falls back to symbol)
|
|
155
169
|
</span>
|
|
156
170
|
<span class='comment'># Json serialization
|
|
157
171
|
</span>
|
|
@@ -234,29 +248,29 @@
|
|
|
234
248
|
<blockquote>
|
|
235
249
|
<p><strong>Performance note:</strong> Rounding-mode support is not loaded by default — <code>require 'minting'</code> uses the fastest possible rounding (equivalent to <code>:half_up</code>) with zero dispatch overhead. The first call to <code>Mint.with_rounding</code> loads the rounding module and patches <code>Currency#normalize_amount</code>, adding ~10–35 ns per money creation or mutation. If your application never uses custom rounding modes (the common case), there is <strong>no performance cost</strong>.</p>
|
|
236
250
|
</blockquote>
|
|
237
|
-
<p><strong>Refinements</strong> — <code>10.dollars</code> and similar helpers require <code>using Mint</code> in the current scope (see Usage above).</p>
|
|
238
251
|
<p><strong>Division</strong> — <code>money / 5</code> returns new <code>Money</code>; <code>money / other_money</code> returns a numeric ratio, not money.</p>
|
|
239
252
|
<p><strong>Zero equality</strong> — Any zero amount is considered equal across currencies and to numeric zero (<code>Mint.money(0, 'USD') == Mint.money(0, 'EUR')</code> is intentionally <code>true</code>). Non-zero amounts must match currency and value.</p>
|
|
240
253
|
<p><strong>Zero helper</strong> — <code>Currency.zero('USD')</code> returns a frozen zero-Money, useful as a default value for discounts, totals, or counters.</p>
|
|
241
254
|
<p><strong>Registered currencies</strong> — <code>Currency.register(code:, subunit:, symbol:, priority:)</code> adds custom currencies. Only registered codes and symbols are recognized by the parser or searches. Nonetheless, you don't need to register a currency to use it with most of the features.</p>
|
|
242
255
|
<p><strong>Built-in currencies</strong> — 150+ ISO-4217 world currencies ship in <code>lib/minting/data/currencies.yaml</code> and load when the registry is first accessed.</p>
|
|
243
256
|
<h2 id="Optional_top_level__Money__and__Currency_">Optional top-level <code>Money</code> and <code>Currency</code></h2>
|
|
244
|
-
<p>By default,
|
|
257
|
+
<p>By default, <code>require "minting"</code> exposes <code>Mint::Money</code> as the top-level <code>Money</code> constant, so you can write <code>Money.from(10, "USD")</code> directly:</p>
|
|
245
258
|
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>minting</span><span class='tstring_end'>"</span></span>
|
|
246
|
-
|
|
247
|
-
</span></
|
|
248
|
-
<
|
|
249
|
-
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="Minting.html" title="Minting (module)">Minting</a></span></span><span class='period'>.</span><span class='id identifier rubyid_use_top_level_constants!'>use_top_level_constants!</span>
|
|
259
|
+
|
|
260
|
+
<span class='id identifier rubyid_price'>price</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from'>from</span><span class='lparen'>(</span><span class='int'>10</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>USD</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='comment'># equivalent to Mint::Money.from
|
|
261
|
+
</span><span class='id identifier rubyid_tax'>tax</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="top-level-namespace.html#Money-constant" title="Money (constant)">Money</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from'>from</span><span class='lparen'>(</span><span class='float'>2.50</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>USD</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
250
262
|
</code></pre>
|
|
251
|
-
<p>
|
|
252
|
-
<pre class="code ruby"><code class="ruby"><span class='
|
|
253
|
-
|
|
263
|
+
<p><code>Currency</code> is <strong>not</strong> auto-bound, because application domain models are commonly named <code>Currency</code> (e.g. a Rails model). To opt in to the top-level <code>Currency</code> constant:</p>
|
|
264
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>minting</span><span class='tstring_end'>"</span></span>
|
|
265
|
+
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>minting/mint/aliases</span><span class='tstring_end'>"</span></span> <span class='comment'># opt-in top-level Currency
|
|
266
|
+
</span>
|
|
267
|
+
<span class='id identifier rubyid_cur'>cur</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="top-level-namespace.html#Currency-constant" title="Currency (constant)">Currency</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>code:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>EUR</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>symbol:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>€</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>subunit:</span> <span class='int'>2</span><span class='comma'>,</span> <span class='label'>priority:</span> <span class='int'>0</span><span class='rparen'>)</span>
|
|
254
268
|
</code></pre>
|
|
255
|
-
<p>
|
|
256
|
-
<pre class="code ruby"><code class="ruby"><span class='
|
|
257
|
-
</span><span class='id identifier
|
|
258
|
-
<span class='id identifier rubyid_cur'>cur</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="top-level-namespace.html#Currency-constant" title="Currency (constant)">Currency</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>code:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>EUR</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>symbol:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>€</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>subunit:</span> <span class='int'>2</span><span class='comma'>,</span> <span class='label'>priority:</span> <span class='int'>0</span><span class='rparen'>)</span>
|
|
269
|
+
<p>For Rails applications, you can enable the top-level <code>Currency</code> constant in an initializer:</p>
|
|
270
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># config/initializers/minting.rb
|
|
271
|
+
</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>minting/mint/aliases</span><span class='tstring_end'>"</span></span>
|
|
259
272
|
</code></pre>
|
|
273
|
+
<p>If another <code>Money</code> is already defined when <code>require "minting"</code> runs (e.g. the <code>money</code> gem was loaded first), Minting warns and skips the auto-bind — use <code>Mint::Money</code> in that case. The same applies to <code>Currency</code> via <code>minting/mint/aliases</code>.</p>
|
|
260
274
|
<p><strong>Good fit:</strong> Application code, especially Rails apps.
|
|
261
275
|
<strong>Not recommended:</strong> Reusable gems/libraries — stick to <code>Mint::Money</code> to avoid conflicts.</p>
|
|
262
276
|
<h2 id="Roadmap">Roadmap</h2>
|
|
@@ -267,7 +281,7 @@
|
|
|
267
281
|
<p>MIT</p></div></div>
|
|
268
282
|
|
|
269
283
|
<div id="footer">
|
|
270
|
-
Generated on
|
|
284
|
+
Generated on Wed Jul 1 01:11:52 2026 by
|
|
271
285
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
272
286
|
0.9.44 (ruby-4.0.5).
|
|
273
287
|
</div>
|