Module: Kernel

Defined in:
lib/g.rb,
lib/g/ruby_gntp.rb,
lib/g/terminal-notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._g_function(&block) ⇒ Object



4
5
6
7
# File 'lib/g.rb', line 4

def self._g_function(&block)
  @_g_function = block if block
  @_g_function
end

Instance Method Details

#g(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/g.rb', line 9

def g(*args)
  messages = args.dup

  if messages.empty?
    if block_given?
      messages << yield(self)
    else
      messages << self
    end
  end

  messages.each do |i|
    text = i.is_a?(String) ? i : i.pretty_inspect
    if Kernel._g_function
      Kernel._g_function.call($0, 'g', text)
    else
      p text
    end
  end

  if args.empty?
    self
  elsif args.size == 1
    args.first
  else
    args
  end
end