Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rust/helpers/string.rb,
lib/naksh/stdlibext.rb

Overview

require File.join(File.dirname(__FILE__), “../syntax/pipes.rb”)

Instance Method Summary collapse

Instance Method Details

#pad(m, d = ' ') ⇒ Object

str.pad(minimum_length,str_to_pad_with=‘ ’) return self if length>minimum_length



42
43
44
45
46
# File 'lib/naksh/stdlibext.rb', line 42

def pad(m,d=' ')
  f = m-length
  return self if f<0
  (d*(f/(d.length*1.0)).ceil)[0,f]<< self
end

#repipe!Object

takes “command1 | command2” and makes it rubyish, like Command.new(command2) | Command.new(command2) OBSOLETE



13
14
15
16
17
# File 'lib/rust/helpers/string.rb', line 13

def repipe!
  commands = self.split('|')
  commands.map! {|com| "Command.new('#{com.strip.sub(' ', '\', \'')}')"}
  self.replace(commands.reverse.join(' | ').strip)
end

#to_commands!Object

OBSOLETE



20
21
22
23
# File 'lib/rust/helpers/string.rb', line 20

def to_commands!
  splits = self.split(' ')
  self.replace "Command.new(#{splits[0]}, #{splits[1..-1]})"
end