module Refinements

Public Instance Methods

cut_both(head = 1, tail = 1) click to toggle source

@return [String] copy of self with first and last lines removed

# File lib/refinements.rb, line 21
def cut_both(head = 1, tail = 1)
  return "" if length.zero?

  each_line.to_a[head..(-1 - tail)].join
end
cut_head(lines = 1) click to toggle source

@return [String] copy of self with first line removed

# File lib/refinements.rb, line 14
def cut_head(lines = 1)
  return "" if length.zero?

  each_line.to_a[lines..-1].join
end
cut_tail(lines = 1) click to toggle source

@return [String] copy of self with last line removed

# File lib/refinements.rb, line 7
def cut_tail(lines = 1)
  return "" if length.zero?

  each_line.to_a[0..(-1 - lines)].join
end
init_from_string(str = '') click to toggle source

Initializes the String instance variables from another String instance when the given str is an instance of String with Oxidized refinements applied

# File lib/refinements.rb, line 35
def init_from_string(str = '')
  raise TypeError unless str.instance_of?(String)

  @cmd  = str.instance_variable_get(:@cmd)
  @name = str.instance_variable_get(:@name)
  @type = str.instance_variable_get(:@type)
end
process_cmd(command) click to toggle source

sets @cmd and @name unless @name is already set

# File lib/refinements.rb, line 28
def process_cmd(command)
  @cmd = command
  @name ||= @cmd.to_s.strip.gsub(/\s+/, '_') # what to do when command is proc? #to_s seems ghetto
end