Class: String

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

Instance Method Summary collapse

Instance Method Details

#divide(by, supprErr = false) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/libsessho.rb', line 38

def divide(by,supprErr=false)
  supprErr||(self.length%by==0||raise(Libsessho::StringNotDivideableError,"Length of string is not divideable by #{by}"))
  retarr = Array.new
  s = self.split("")
  until s.empty?
    retarr.push s.shift(by)
  end
  return retarr.map(&:join)
end

#dropFileEndingObject



47
48
49
# File 'lib/libsessho.rb', line 47

def dropFileEnding
  self.split(".").reverse[1,self.length].reverse.join(".")
end

#matches(s) ⇒ Object



50
51
52
53
54
# File 'lib/libsessho.rb', line 50

def matches(s)
  matcharr = Array.new
  self.split("").each_with_index{|c,i|c==s&&matcharr<<i}
  return matcharr
end

#splitAt(pos) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
# File 'lib/libsessho.rb', line 24

def splitAt(pos)
  raise ArgumentError,"Index out of range" if pos>=self.length
  p2 = self.split("")
  p1 = p2.shift(pos)
  [p1,p2].map(&:join)
end

#substr(pos) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
# File 'lib/libsessho.rb', line 30

def substr(pos)
  raise ArgumentError,"Index out of range" if pos>=self.length
  self[pos,self.length]
end

#supstr(pos) ⇒ Object

Raises:

  • (ArgumentError)


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

def supstr(pos)
  raise ArgumentError,"Index out of range" if pos>=self.length
  self[0,pos]
end