Sha256: d41b2ebb58d7ff645bbf99dfa60d4cec2a39fb2fa7a2cf875176ade9a55d68e6

Contents?: true

Size: 508 Bytes

Versions: 2

Compression:

Stored size: 508 Bytes

Contents

# Extending the Symbol class.
#
class Symbol
  
  # :keys.each_subtoken    # => yields each of [:keys, :key, :ke, :k]
  # :keys.each_subtoken(2) # => yields each of [:keys, :key, :ke]
  #
  def each_subtoken from_length = 1
    sub = self.id2name
    
    size = sub.size
    from_length = size + from_length + 1 if from_length < 0
    from_length = size if size < from_length
    from_length = 1 if from_length < 1
    
    yield self
    size.downto(from_length + 1) { yield sub.chop!.intern }
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
picky-0.12.3 lib/picky/extensions/symbol.rb
picky-0.12.2 lib/picky/extensions/symbol.rb