Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/libsessho.rb
Instance Method Summary collapse
- #divide(by, supprErr = false) ⇒ Object
- #dropFileEnding ⇒ Object
- #matches(s) ⇒ Object
- #splitAt(pos) ⇒ Object
- #substr(pos) ⇒ Object
- #supstr(pos) ⇒ Object
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 |
#dropFileEnding ⇒ Object
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
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
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
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 |