Module: Ruuuby::Feature::Includable::StringF21
- Included in:
- String
- Defined in:
- lib/ruuuby/class/str/str.rb
Overview
defines the operations needed to support Feature(f21) that are applied to Class(String)
Instance Method Summary collapse
-
#digit? ⇒ Boolean
True, if this
Stringis length 1 with a it’s character being a digit (ascii value between 48 and 57). - #to_num ⇒ Numeric, ...
-
#to_num? ⇒ Boolean
True, if this
Stringcan be converted into a number w/o raising any exception.
Instance Method Details
#digit? ⇒ Boolean
Returns true, if this String is length 1 with a it’s character being a digit (ascii value between 48 and 57).
174 |
# File 'lib/ruuuby/class/str/str.rb', line 174 def digit?; self.𝔠₁? && self.ord < 58 && self.ord > 47; end |
#to_num ⇒ Numeric, ...
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/ruuuby/class/str/str.rb', line 187 def to_num if 𝕊.∋?(self) return 𝕊.parse(self) end case(self.length) when 0 🛑 ::Ruuuby::DescriptiveStandardError.🆕(self, "can't be parsed as a num") when 1 if self.digit? return self.to_i else 🛑 ::Ruuuby::DescriptiveStandardError.🆕(self, "can't be parsed as a num") end when 2 case(self.₀) when '.' if self.₁.digit? return Float(self) else 🛑 ::Ruuuby::DescriptiveStandardError.🆕(self, "can't be parsed as a num") end when '+', '-' if self.₁.digit? ; return Integer(self) elsif self.₁?('π') ; return (self.₀?('-')) ? (-::Math::PI) : (::Math::PI) else ; 🛑 ::Ruuuby::DescriptiveStandardError.🆕(self, "can't be parsed as a num") end else if self.₀.digit? && self.₁.digit? ; return Integer(self) else ; 🛑 ::Ruuuby::DescriptiveStandardError.🆕(self, "can't be parsed as a num") end end when 3 if self.match?(String.syntax_len_3_as_flt) ; return Float(self) elsif self.match?(String.syntax_len_3_as_int) ; return Integer(self) elsif self.downcase == 'nan' ; return Float::NAN else ; 🛑 ::Ruuuby::DescriptiveStandardError.🆕(self, "can't be parsed as a num") end else if self.match?(String.syntax_len_any_as_int) ; return Integer(self) elsif self.match?(String.syntax_len_any) ; return Float(self) else ; 🛑 ::Ruuuby::DescriptiveStandardError.🆕(self, "can't be parsed as a num") end end end |
#to_num? ⇒ Boolean
Returns true, if this String can be converted into a number w/o raising any exception.
177 178 179 180 181 182 |
# File 'lib/ruuuby/class/str/str.rb', line 177 def to_num? self.to_num true rescue false end |