Module: KoremuFixnumFunctions
Overview
KoremuFixnumFunctions
The following functions are either available through the KoremuFixnum class, or can be included in other classes. For example, maybe the most natural use would be by including them in the Fixnum class. You can include them by typing this in your initialization:
class Fixnum; include KoremuFixnumFunctions; end
This way, any arbitrary string can be treated as a KoremuString:
puts 27494288.to_ks # FEFIFOFU
puts 27494288.to_ka # [13, 14, 15, 16]
If you choose not to extend Fixnum, you can use KoremuFixnum as a regular class, initializing it with the number in question:
ks = KoremuFixnum.new(1024**4 + 1024**3 + 1024**2 + 1024) # JIBUBAPUDIBA
Constant Summary
Constants included from Koremutake
Koremutake::Phonemes, Koremutake::Vowels
Instance Method Summary collapse
-
#initialize(val) ⇒ Object
:nodoc:.
-
#to_ka ⇒ Object
Returns the KoremuArray representation of the KoremuFixmum.
-
#to_ks ⇒ Object
Returns the KoremuString representatiion of the KoremuFixnum.
Instance Method Details
#initialize(val) ⇒ Object
:nodoc:
154 155 156 157 158 |
# File 'lib/koremu.rb', line 154 def initialize(val) #:nodoc: raise InvalidKoremutake, 'Negative values not defined' if val < 0 val = val.to_i || 0 super(val) end |
#to_ka ⇒ Object
Returns the KoremuArray representation of the KoremuFixmum
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/koremu.rb', line 161 def to_ka raise InvalidKoremutake, 'Negative values not defined' if self < 0 return KoremuArray.new([0]) if self == 0 res = KoremuArray.new num = self while num > 0 res.unshift num%128 num = KoremuFixnum.new(num/128) end res end |
#to_ks ⇒ Object
Returns the KoremuString representatiion of the KoremuFixnum
174 175 176 |
# File 'lib/koremu.rb', line 174 def to_ks self.to_ka.to_ks end |