-
Notifications
You must be signed in to change notification settings - Fork 19
/
g.rb
49 lines (43 loc) · 833 Bytes
/
g.rb
1
2
3
4
5
6
7
8
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
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'pp'
module Kernel
def self._g_function(&block)
@_g_function = block if block
@_g_function
end
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
end
catch(:break) do
%w(terminal-notifier ruby_gntp).each do |lib|
begin
require lib
require "g/#{lib}"
throw :break
rescue LoadError
end
end
warn 'Please install `terminal-notifier` or `ruby_gntp`.'
end