code-ruby 0.5.6 → 0.6.1

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.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -3
  3. data/Gemfile.lock +11 -21
  4. data/README.md +2 -102
  5. data/bin/code +34 -16
  6. data/code-ruby.gemspec +5 -3
  7. data/lib/code/error.rb +16 -5
  8. data/lib/code/node/base_10.rb +4 -2
  9. data/lib/code/node/base_16.rb +3 -1
  10. data/lib/code/node/base_2.rb +3 -1
  11. data/lib/code/node/base_8.rb +3 -1
  12. data/lib/code/node/boolean.rb +4 -2
  13. data/lib/code/node/call.rb +35 -12
  14. data/lib/code/node/call_argument.rb +16 -5
  15. data/lib/code/node/code.rb +5 -4
  16. data/lib/code/node/decimal.rb +2 -0
  17. data/lib/code/node/{dictionnary.rb → dictionary.rb} +14 -5
  18. data/lib/code/node/function.rb +7 -4
  19. data/lib/code/node/function_parameter.rb +3 -1
  20. data/lib/code/node/if.rb +5 -3
  21. data/lib/code/node/left_operation.rb +63 -0
  22. data/lib/code/node/list.rb +2 -0
  23. data/lib/code/node/negation.rb +2 -0
  24. data/lib/code/node/not.rb +2 -0
  25. data/lib/code/node/nothing.rb +3 -1
  26. data/lib/code/node/number.rb +2 -0
  27. data/lib/code/node/right_operation.rb +70 -0
  28. data/lib/code/node/splat.rb +2 -0
  29. data/lib/code/node/square_bracket.rb +37 -0
  30. data/lib/code/node/statement.rb +13 -5
  31. data/lib/code/node/string.rb +3 -1
  32. data/lib/code/node/ternary.rb +5 -3
  33. data/lib/code/node/unary_minus.rb +2 -0
  34. data/lib/code/node/while.rb +6 -4
  35. data/lib/code/node.rb +11 -5
  36. data/lib/code/object/argument.rb +13 -7
  37. data/lib/code/object/boolean.rb +43 -5
  38. data/lib/code/object/class.rb +17 -0
  39. data/lib/code/object/context.rb +36 -0
  40. data/lib/code/object/decimal.rb +252 -100
  41. data/lib/code/object/dictionary.rb +641 -0
  42. data/lib/code/object/function.rb +54 -27
  43. data/lib/code/object/global.rb +65 -19
  44. data/lib/code/object/identifier_list.rb +47 -0
  45. data/lib/code/object/integer.rb +320 -137
  46. data/lib/code/object/list.rb +140 -138
  47. data/lib/code/object/nothing.rb +10 -4
  48. data/lib/code/object/number.rb +6 -1
  49. data/lib/code/object/range.rb +85 -88
  50. data/lib/code/object/ruby_function.rb +11 -6
  51. data/lib/code/object/string.rb +51 -48
  52. data/lib/code/object.rb +117 -139
  53. data/lib/code/parser/addition.rb +4 -2
  54. data/lib/code/parser/and_operator.rb +4 -2
  55. data/lib/code/parser/bitwise_and.rb +4 -2
  56. data/lib/code/parser/bitwise_or.rb +4 -2
  57. data/lib/code/parser/boolean.rb +3 -1
  58. data/lib/code/parser/call.rb +17 -11
  59. data/lib/code/parser/chained_call.rb +10 -22
  60. data/lib/code/parser/class.rb +9 -6
  61. data/lib/code/parser/code.rb +6 -4
  62. data/lib/code/parser/{dictionnary.rb → dictionary.rb} +16 -13
  63. data/lib/code/parser/equal.rb +9 -36
  64. data/lib/code/parser/equality.rb +4 -2
  65. data/lib/code/parser/function.rb +24 -9
  66. data/lib/code/parser/greater.rb +6 -3
  67. data/lib/code/parser/group.rb +4 -2
  68. data/lib/code/parser/if.rb +6 -4
  69. data/lib/code/parser/if_modifier.rb +5 -25
  70. data/lib/code/parser/left_operation.rb +40 -0
  71. data/lib/code/parser/list.rb +6 -5
  72. data/lib/code/parser/multiplication.rb +4 -2
  73. data/lib/code/parser/name.rb +19 -4
  74. data/lib/code/parser/negation.rb +4 -2
  75. data/lib/code/parser/not_keyword.rb +5 -3
  76. data/lib/code/parser/nothing.rb +3 -10
  77. data/lib/code/parser/number.rb +4 -2
  78. data/lib/code/parser/or_keyword.rb +4 -2
  79. data/lib/code/parser/or_operator.rb +4 -2
  80. data/lib/code/parser/power.rb +4 -28
  81. data/lib/code/parser/range.rb +4 -2
  82. data/lib/code/parser/rescue.rb +6 -26
  83. data/lib/code/parser/right_operation.rb +40 -0
  84. data/lib/code/parser/shift.rb +4 -2
  85. data/lib/code/parser/splat.rb +5 -3
  86. data/lib/code/parser/square_bracket.rb +48 -0
  87. data/lib/code/parser/statement.rb +3 -1
  88. data/lib/code/parser/string.rb +12 -10
  89. data/lib/code/parser/ternary.rb +10 -11
  90. data/lib/code/parser/unary_minus.rb +5 -3
  91. data/lib/code/parser/while.rb +5 -3
  92. data/lib/code/parser/whitespace.rb +2 -0
  93. data/lib/code/parser.rb +10 -3
  94. data/lib/code/ruby.rb +4 -2
  95. data/lib/code/type/hash.rb +38 -0
  96. data/lib/code/type/maybe.rb +29 -0
  97. data/lib/code/type/or.rb +38 -0
  98. data/lib/code/type/repeat.rb +38 -0
  99. data/lib/code/type/sig.rb +130 -0
  100. data/lib/code/type.rb +25 -0
  101. data/lib/code/version.rb +3 -0
  102. data/lib/code-ruby.rb +1 -2
  103. data/lib/code.rb +15 -16
  104. data/spec/code/node/call_spec.rb +39 -0
  105. data/spec/code/object/boolean_spec.rb +18 -0
  106. data/spec/code/object/decimal_spec.rb +51 -0
  107. data/spec/code/object/dictionary_spec.rb +98 -0
  108. data/spec/code/object/function_spec.rb +42 -0
  109. data/spec/code/object/integer_spec.rb +43 -0
  110. data/spec/code/object/nothing_spec.rb +14 -0
  111. data/spec/code/object/range_spec.rb +23 -0
  112. data/spec/code/parser/boolean_spec.rb +5 -10
  113. data/spec/code/parser/chained_call.rb +4 -5
  114. data/spec/code/parser/{dictionnary_spec.rb → dictionary_spec.rb} +5 -6
  115. data/spec/code/parser/function_spec.rb +4 -5
  116. data/spec/code/parser/group_spec.rb +5 -12
  117. data/spec/code/parser/if_modifier_spec.rb +18 -0
  118. data/spec/code/parser/list_spec.rb +4 -5
  119. data/spec/code/parser/number_spec.rb +4 -5
  120. data/spec/code/parser/string_spec.rb +4 -5
  121. data/spec/code/parser_spec.rb +22 -16
  122. data/spec/code/type_spec.rb +21 -0
  123. data/spec/code_spec.rb +171 -0
  124. data/spec/spec_helper.rb +1 -6
  125. metadata +63 -136
  126. data/.cherry.js +0 -21
  127. data/.editorconfig +0 -9
  128. data/.github/workflows/rspec.yml +0 -14
  129. data/.gitignore +0 -2
  130. data/.prettierrc +0 -3
  131. data/.tool-versions +0 -1
  132. data/CHANGELOG.md +0 -55
  133. data/LICENSE +0 -7
  134. data/TODO +0 -17
  135. data/bin/format +0 -3
  136. data/bin/publish +0 -19
  137. data/bin/template +0 -85
  138. data/bin/test +0 -17
  139. data/docs/class.code +0 -9
  140. data/docs/euler/1.template +0 -10
  141. data/docs/euler/2.template +0 -16
  142. data/docs/euler/3.template +0 -16
  143. data/docs/euler/4.template +0 -10
  144. data/docs/euler/5.template +0 -13
  145. data/docs/fibonnaci.template +0 -14
  146. data/docs/meetup.code +0 -12
  147. data/docs/precedence.template +0 -36
  148. data/docs/rain.code +0 -22
  149. data/docs/slack.code +0 -17
  150. data/docs/stripe.code +0 -7
  151. data/docs/twitter.code +0 -9
  152. data/language-ruby.gemspec +0 -17
  153. data/lib/code/node/chained_call.rb +0 -23
  154. data/lib/code/node/equal.rb +0 -34
  155. data/lib/code/node/if_modifier.rb +0 -47
  156. data/lib/code/node/operation.rb +0 -38
  157. data/lib/code/node/power.rb +0 -20
  158. data/lib/code/node/rescue.rb +0 -17
  159. data/lib/code/object/dictionnary.rb +0 -96
  160. data/lib/code/parser/equality_lower.rb +0 -9
  161. data/lib/code/parser/operation.rb +0 -35
  162. data/lib/language/atom.rb +0 -342
  163. data/lib/language/output.rb +0 -130
  164. data/lib/language/parser/absent/present.rb +0 -8
  165. data/lib/language/parser/absent.rb +0 -6
  166. data/lib/language/parser/end_of_input.rb +0 -6
  167. data/lib/language/parser/interuption.rb +0 -38
  168. data/lib/language/parser/not_end_of_input.rb +0 -6
  169. data/lib/language/parser/str/not_found.rb +0 -16
  170. data/lib/language/parser/str.rb +0 -6
  171. data/lib/language/parser.rb +0 -53
  172. data/lib/language-ruby.rb +0 -10
  173. data/lib/language.rb +0 -80
  174. data/lib/template/node/code_part.rb +0 -13
  175. data/lib/template/node/part.rb +0 -19
  176. data/lib/template/node/template.rb +0 -15
  177. data/lib/template/node/text_part.rb +0 -13
  178. data/lib/template/node.rb +0 -4
  179. data/lib/template/parser/template.rb +0 -39
  180. data/lib/template/parser.rb +0 -19
  181. data/lib/template/version.rb +0 -3
  182. data/lib/template-ruby.rb +0 -10
  183. data/lib/template.rb +0 -50
  184. data/spec/code/addition_spec.rb +0 -13
  185. data/spec/code/and_operator_spec.rb +0 -13
  186. data/spec/code/bitwise_and_spec.rb +0 -13
  187. data/spec/code/bitwise_or_spec.rb +0 -13
  188. data/spec/code/boolean_spec.rb +0 -13
  189. data/spec/code/call_spec.rb +0 -21
  190. data/spec/code/chained_call_spec.rb +0 -16
  191. data/spec/code/code_spec.rb +0 -29
  192. data/spec/code/dictionnary_spec.rb +0 -17
  193. data/spec/code/equal_spec.rb +0 -26
  194. data/spec/code/equality_spec.rb +0 -13
  195. data/spec/code/function_spec.rb +0 -18
  196. data/spec/code/greater_spec.rb +0 -18
  197. data/spec/code/group_spec.rb +0 -12
  198. data/spec/code/if_modifier_spec.rb +0 -20
  199. data/spec/code/if_spec.rb +0 -25
  200. data/spec/code/list_spec.rb +0 -19
  201. data/spec/code/multiplication_spec.rb +0 -18
  202. data/spec/code/negation_spec.rb +0 -20
  203. data/spec/code/not_keyword_spec.rb +0 -13
  204. data/spec/code/nothing_spec.rb +0 -17
  205. data/spec/code/number_spec.rb +0 -22
  206. data/spec/code/or_keyword_spec.rb +0 -17
  207. data/spec/code/or_operator_spec.rb +0 -16
  208. data/spec/code/parser/call_spec.rb +0 -26
  209. data/spec/code/power_spec.rb +0 -13
  210. data/spec/code/range_spec.rb +0 -16
  211. data/spec/code/rescue_spec.rb +0 -13
  212. data/spec/code/shift_spec.rb +0 -13
  213. data/spec/code/splat_spec.rb +0 -13
  214. data/spec/code/string_spec.rb +0 -27
  215. data/spec/code/ternary_spec.rb +0 -18
  216. data/spec/code/unary_minus_spec.rb +0 -13
  217. data/spec/code/while_spec.rb +0 -18
  218. data/template-ruby.gemspec +0 -19
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Code
2
4
  class Object
3
5
  class Decimal < ::Code::Object::Number
@@ -6,13 +8,16 @@ class Code
6
8
  def initialize(decimal, exponent: nil)
7
9
  @raw = BigDecimal(decimal)
8
10
 
9
- if exponent
10
- if exponent.is_a?(::Code::Object::Number)
11
- @raw = @raw * 10**exponent.raw
12
- else
13
- raise ::Code::Error::TypeError.new("exponent is not a number")
14
- end
11
+ return unless exponent
12
+ unless exponent.is_a?(Number)
13
+ raise ::Code::Error::TypeError, "exponent is not a number"
15
14
  end
15
+
16
+ @raw *= 10**exponent.raw
17
+ end
18
+
19
+ def self.name
20
+ "Decimal"
16
21
  end
17
22
 
18
23
  def call(**args)
@@ -20,142 +25,289 @@ class Code
20
25
  arguments = args.fetch(:arguments, [])
21
26
  value = arguments.first&.value
22
27
 
23
- if operator == "%"
24
- sig(arguments) { ::Code::Object::Number }
25
- modulo(value)
26
- elsif operator == "+"
27
- if value
28
- sig(arguments) { ::Code::Object }
29
- plus(value)
30
- else
31
- sig(arguments)
32
- self
33
- end
34
- elsif operator == "-"
35
- if value
36
- sig(arguments) { ::Code::Object::Number }
37
- minus(value)
38
- else
39
- sig(arguments)
40
- unary_minus
41
- end
42
- elsif operator == "/"
43
- sig(arguments) { ::Code::Object::Number }
44
- division(value)
45
- elsif operator == "*"
46
- sig(arguments) { ::Code::Object::Number }
47
- multiplication(value)
48
- elsif operator == "**"
49
- sig(arguments) { ::Code::Object::Number }
50
- power(value)
51
- elsif operator == "<"
52
- sig(arguments) { ::Code::Object::Number }
53
- inferior(value)
54
- elsif operator == "<="
55
- sig(arguments) { ::Code::Object::Number }
56
- inferior_or_equal(value)
57
- elsif operator == ">"
58
- sig(arguments) { ::Code::Object::Number }
59
- superior(value)
60
- elsif operator == ">="
61
- sig(arguments) { ::Code::Object::Number }
62
- superior_or_equal(value)
63
- elsif operator == "<<"
64
- sig(arguments) { ::Code::Object::Number }
65
- left_shift(value)
66
- elsif operator == ">>"
67
- sig(arguments) { ::Code::Object::Number }
68
- right_shift(value)
69
- elsif operator == "&"
70
- sig(arguments) { ::Code::Object::Number }
71
- bitwise_and(value)
72
- elsif operator == "|"
73
- sig(arguments) { ::Code::Object::Number }
74
- bitwise_or(value)
75
- elsif operator == "^"
76
- sig(arguments) { ::Code::Object::Number }
77
- bitwise_xor(value)
28
+ case operator.to_s
29
+ when "%", "modulo"
30
+ sig(args) { Number }
31
+ code_modulo(value)
32
+ when "&", "bitwise_and"
33
+ sig(args) { Number }
34
+ code_bitwise_and(value)
35
+ when "*", "multiplication"
36
+ sig(args) { Number }
37
+ code_multiplication(value)
38
+ when "**", "power"
39
+ sig(args) { Number }
40
+ code_power(value)
41
+ when "+", "plus"
42
+ sig(args) { Object.maybe }
43
+ value ? code_plus(value) : self
44
+ when "-", "minus"
45
+ sig(args) { Number.maybe }
46
+ value ? code_minus(value) : code_unary_minus
47
+ when "/", "division"
48
+ sig(args) { Number }
49
+ code_division(value)
50
+ when "<", "inferior"
51
+ sig(args) { Number }
52
+ code_inferior(value)
53
+ when "<<", "left_shift"
54
+ sig(args) { Number }
55
+ code_left_shift(value)
56
+ when "<=", "inferior_or_equal"
57
+ sig(args) { Number }
58
+ code_inferior_or_equal(value)
59
+ when "<=>", "compare"
60
+ sig(args) { Number }
61
+ code_compare(value)
62
+ when ">", "superior"
63
+ sig(args) { Number }
64
+ code_superior(value)
65
+ when ">=", "superior_or_equal"
66
+ sig(args) { Number }
67
+ code_superior_or_equal(value)
68
+ when ">>", "right_shift"
69
+ sig(args) { Number }
70
+ code_right_shift(value)
71
+ when "^", "bitwise_xor"
72
+ sig(args) { Number }
73
+ code_bitwise_xor(value)
74
+ when "abs"
75
+ sig(args)
76
+ code_abs
77
+ when "ceil"
78
+ sig(args) { Integer.maybe }
79
+ code_ceil(value)
80
+ when "clone"
81
+ sig(args)
82
+ code_clone
83
+ when "eight?"
84
+ sig(args)
85
+ code_eight?
86
+ when "five?"
87
+ sig(args)
88
+ code_five?
89
+ when "floor"
90
+ sig(args) { Integer.maybe }
91
+ code_floor(value)
92
+ when "four?"
93
+ sig(args)
94
+ code_four?
95
+ when "nine?"
96
+ sig(args)
97
+ code_nine?
98
+ when "one?"
99
+ sig(args)
100
+ code_one?
101
+ when "round"
102
+ sig(args) { Integer.maybe }
103
+ code_round(value)
104
+ when "seven?"
105
+ sig(args)
106
+ code_seven?
107
+ when "six?"
108
+ sig(args)
109
+ code_six?
110
+ when "sqrt"
111
+ sig(args)
112
+ code_sqrt
113
+ when "ten?"
114
+ sig(args)
115
+ code_ten?
116
+ when "three?"
117
+ sig(args)
118
+ code_three?
119
+ when "to_decimal"
120
+ sig(args)
121
+ code_to_decimal
122
+ when "to_integer"
123
+ sig(args)
124
+ code_to_integer
125
+ when "to_string"
126
+ sig(args)
127
+ code_to_string
128
+ when "truncate"
129
+ sig(args) { Integer.maybe }
130
+ code_truncate(value)
131
+ when "two?"
132
+ sig(args)
133
+ code_two?
134
+ when "zero?"
135
+ sig(args)
136
+ code_zero?
137
+ when "|", "bitwise_or"
138
+ sig(args) { Number }
139
+ code_bitwise_or(value)
78
140
  else
79
141
  super
80
142
  end
81
143
  end
82
144
 
83
- def to_s
84
- raw.to_s("F")
145
+ def code_abs
146
+ Decimal.new(raw.abs)
85
147
  end
86
148
 
87
- def inspect
88
- to_s
149
+ def code_bitwise_and(other)
150
+ Integer.new(raw.to_i & other.raw.to_i)
151
+ end
152
+
153
+ def code_bitwise_or(other)
154
+ Integer.new(raw.to_i | other.raw.to_i)
155
+ end
156
+
157
+ def code_bitwise_xor(other)
158
+ Integer.new(raw.to_i ^ other.raw.to_i)
159
+ end
160
+
161
+ def code_ceil(n = nil)
162
+ n ||= Integer.new(0)
163
+ Decimal.new(raw.ceil(n.raw))
89
164
  end
90
165
 
91
- private
166
+ def code_clone
167
+ Decimal.new(raw)
168
+ end
169
+
170
+ def code_compare(other)
171
+ Integer.new(raw <=> other.raw)
172
+ end
173
+
174
+ def code_division(other)
175
+ Decimal.new(raw / other.raw)
176
+ end
177
+
178
+ def code_eight?
179
+ Boolean.new(raw == 8)
180
+ end
92
181
 
93
- def modulo(other)
94
- ::Code::Object::Decimal.new(raw % other.raw)
182
+ def code_five?
183
+ Boolean.new(raw == 5)
95
184
  end
96
185
 
97
- def plus(other)
98
- if other.is_a?(::Code::Object::Number)
99
- ::Code::Object::Decimal.new(raw + other.raw)
186
+ def code_floor(n = nil)
187
+ n ||= Integer.new(0)
188
+ Decimal.new(raw.floor(n.raw))
189
+ end
190
+
191
+ def code_four?
192
+ Boolean.new(raw == 4)
193
+ end
194
+
195
+ def code_inferior(other)
196
+ Boolean.new(raw < other.raw)
197
+ end
198
+
199
+ def code_inferior_or_equal(other)
200
+ Boolean.new(raw <= other.raw)
201
+ end
202
+
203
+ def code_left_shift(other)
204
+ Integer.new(raw.to_i << other.raw.to_i)
205
+ end
206
+
207
+ def code_minus(other)
208
+ Decimal.new(raw - other.raw)
209
+ end
210
+
211
+ def code_modulo(other)
212
+ Decimal.new(raw % other.raw)
213
+ end
214
+
215
+ def code_multiplication(other)
216
+ Decimal.new(raw * other.raw)
217
+ end
218
+
219
+ def code_nine?
220
+ Boolean.new(raw == 9)
221
+ end
222
+
223
+ def code_one?
224
+ Boolean.new(raw == 1)
225
+ end
226
+
227
+ def code_plus(other)
228
+ if other.is_a?(Number)
229
+ Decimal.new(raw + other.raw)
100
230
  else
101
- ::Code::Object::String.new(to_s + other.to_s)
231
+ String.new(to_s + other.to_s)
102
232
  end
103
233
  end
104
234
 
105
- def minus(other)
106
- ::Code::Object::Decimal.new(raw - other.raw)
235
+ def code_power(other)
236
+ Decimal.new(raw**other.raw)
107
237
  end
108
238
 
109
- def division(other)
110
- ::Code::Object::Decimal.new(raw / other.raw)
239
+ def code_right_shift(other)
240
+ Integer.new(raw.to_i >> other.raw.to_i)
111
241
  end
112
242
 
113
- def multiplication(other)
114
- ::Code::Object::Decimal.new(raw * other.raw)
243
+ def code_round(n = nil)
244
+ n ||= Integer.new(0)
245
+ Decimal.new(raw.round(n.raw))
115
246
  end
116
247
 
117
- def power(other)
118
- ::Code::Object::Decimal.new(raw**other.raw)
248
+ def code_seven?
249
+ Boolean.new(raw == 7)
119
250
  end
120
251
 
121
- def inferior(other)
122
- ::Code::Object::Boolean.new(raw < other.raw)
252
+ def code_six?
253
+ Boolean.new(raw == 6)
123
254
  end
124
255
 
125
- def inferior_or_equal(other)
126
- ::Code::Object::Boolean.new(raw <= other.raw)
256
+ def code_sqrt
257
+ Decimal.new(Math.sqrt(raw).to_s)
127
258
  end
128
259
 
129
- def superior(other)
130
- ::Code::Object::Boolean.new(raw > other.raw)
260
+ def code_superior(other)
261
+ Boolean.new(raw > other.raw)
131
262
  end
132
263
 
133
- def superior_or_equal(other)
134
- ::Code::Object::Boolean.new(raw >= other.raw)
264
+ def code_superior_or_equal(other)
265
+ Boolean.new(raw >= other.raw)
135
266
  end
136
267
 
137
- def left_shift(other)
138
- ::Code::Object::Integer.new(raw.to_i << other.raw.to_i)
268
+ def code_ten?
269
+ Boolean.new(raw == 10)
139
270
  end
140
271
 
141
- def right_shift(other)
142
- ::Code::Object::Integer.new(raw.to_i >> other.raw.to_i)
272
+ def code_three?
273
+ Boolean.new(raw == 3)
143
274
  end
144
275
 
145
- def bitwise_and(other)
146
- ::Code::Object::Integer.new(raw.to_i & other.raw.to_i)
276
+ def code_to_decimal
277
+ Decimal.new(raw)
147
278
  end
148
279
 
149
- def bitwise_or(other)
150
- ::Code::Object::Integer.new(raw.to_i | other.raw.to_i)
280
+ def code_to_integer
281
+ Integer.new(raw.to_i)
151
282
  end
152
283
 
153
- def bitwise_xor(other)
154
- ::Code::Object::Integer.new(raw.to_i ^ other.raw.to_i)
284
+ def code_to_string
285
+ String.new(raw.to_s("F"))
155
286
  end
156
287
 
157
- def unary_minus
158
- ::Code::Object::Decimal.new(-raw)
288
+ def code_truncate(n = nil)
289
+ n ||= Integer.new(0)
290
+ Decimal.new(raw.truncate(n.raw))
291
+ end
292
+
293
+ def code_two?
294
+ Boolean.new(raw == 2)
295
+ end
296
+
297
+ def code_unary_minus
298
+ Decimal.new(-raw)
299
+ end
300
+
301
+ def code_zero?
302
+ Boolean.new(raw.zero?)
303
+ end
304
+
305
+ def inspect
306
+ to_s
307
+ end
308
+
309
+ def to_s
310
+ raw.to_s("F")
159
311
  end
160
312
  end
161
313
  end