Module: Putsplus

Defined in:
lib/putsplus.rb,
lib/putsplus/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Instance Method Details

#linebr(num = 6, char = '-') ⇒ Object

Puts a line break with given character and length

Arguments:

num: number of times to repeat the given character. Default is 6.
char: the character or string to repeat. Default is '-'

Raises:

  • (Exeception)


36
37
38
39
40
41
# File 'lib/putsplus.rb', line 36

def linebr num = 6, char = '-'
  raise Exeception, "num must be an Integer" unless is_int?(num)
  raise Exeception, "char must be an Character or String" unless (is_string? char)

  puts char * num
end

#nputs(obj, prefix = nil) ⇒ Object

Puts only if obj is not null

Arguments: obj: the obj that will be puts if it isn’t null prefix: obj to append to the puts if obj isn’t null



11
12
13
# File 'lib/putsplus.rb', line 11

def nputs obj, prefix = nil
  puts prefix.to_s +  obj.to_s unless obj.nil?
end

#tputs(*obj) ⇒ Object

Puts each parameter with a tab inbetween each



19
20
21
22
23
24
25
26
27
# File 'lib/putsplus.rb', line 19

def tputs *obj
  out = ""
  obj.each_with_index do |o, index|
    s = o.to_s
    s += "\t" unless index == obj.size - 1
    out << s      
  end
  puts out
end