Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/andy_convenience.rb

Instance Method Summary collapse

Instance Method Details

#-(n) ⇒ Object



21
22
23
24
25
# File 'lib/andy_convenience.rb', line 21

def -(n)
  str = self
  n.times { str = str.chop }
  str
end

#/(n) ⇒ Object



27
28
29
30
31
32
# File 'lib/andy_convenience.rb', line 27

def /(n)
  left = self.size % n
  reg = Regexp.new(".{#{n}}")
  res = self.scan(reg)
  res += [self[(0 - left)..-1]]
end

#crunch(str) ⇒ Object



17
18
19
# File 'lib/andy_convenience.rb', line 17

def crunch(str)
  str.chars.chunk{|s| s}.map(&:first).join
end

#idx(coll) ⇒ Object



46
47
48
# File 'lib/andy_convenience.rb', line 46

def idx(coll)
  coll[self.to_i - 1]
end

#increment(interval = 1, operator = :+, seq = 1) ⇒ Object Also known as: stinc



38
39
40
# File 'lib/andy_convenience.rb', line 38

def increment(interval = 1, operator = :+, seq = 1)
  self.to_i.increment(interval, operator, seq)
end

#indexment(coll, interval = 1, operator = :+, seq = 1) ⇒ Object Also known as: idxmt



42
43
44
# File 'lib/andy_convenience.rb', line 42

def indexment(coll, interval = 1, operator = :+, seq = 1)
  coll[self.increment(interval, operator, seq)]
end

#stringcrement(interval = 1, operator = :+, seq = 1) ⇒ Object Also known as: strc



34
35
36
# File 'lib/andy_convenience.rb', line 34

def stringcrement(interval = 1, operator = :+, seq = 1)
  self.to_i.stringcrement(interval, operator, seq)
end

#to_binaryObject



4
5
6
7
8
# File 'lib/andy_convenience.rb', line 4

def to_binary
  ascii = []
  self.each_byte {|char| ascii << char}
  ascii.map{ |n| n.to_binary }.join(' ')
end

#webitize(tag, options = nil) ⇒ Object Also known as: to_web



10
11
12
13
14
15
# File 'lib/andy_convenience.rb', line 10

def webitize(tag, options = nil)
  if options
    options = ' ' + (options.map {|k, v| "#{k}='#{v}'"}.join(' '))
  end
  "<#{tag}#{options}>#{self}</#{tag}>"
end