Sha256: 90ca393934a0bd918d59cc5af18865b07804a286bc3312dae9de7c6a41f926dc
Contents?: true
Size: 788 Bytes
Versions: 2
Compression:
Stored size: 788 Bytes
Contents
# Extending the Symbol class. # class Symbol # :keys.subtokens # => [:keys, :key, :ke, :k] # :keys.subtokens(2) # => [:keys, :key, :ke] # def subtokens down_to_length = 1 sub = self.id2name size = sub.size down_to_length = size + down_to_length if down_to_length < 0 down_to_length = size if size < down_to_length result = [self] size.downto(down_to_length + 1) { result << sub.chop!.intern } result end # TODO Duplicate code. # def each_subtoken down_to_length = 1 sub = self.id2name size = sub.size down_to_length = size + down_to_length if down_to_length < 0 down_to_length = size if size < down_to_length yield self size.downto(down_to_length + 1) { yield sub.chop!.intern } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
picky-0.2.0 | lib/picky/extensions/symbol.rb |
picky-0.1.0 | lib/picky/extensions/symbol.rb |