Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve for debugging

  • Loading branch information...
commit 77c3406a4d8dba92085631db2cc41e70f2932e84 1 parent 68ec8c2
@jugyo authored
Showing with 24 additions and 23 deletions.
  1. +12 −11 lib/g.rb
  2. +12 −12 spec/g_spec.rb
View
23 lib/g.rb
@@ -7,23 +7,24 @@
$g_sticky ||= true
module Kernel
- def g(*args, &block)
- # growl = Growl.new $g_host, 'g', [$0]
+ def g(*args)
+ messages = args.dup
- args.push(block) if block
-
- messages =
- if args.empty?
- ['g!']
+ if messages.empty?
+ if block_given?
+ messages << yield(self)
else
- args.map { |i| i.pretty_inspect }
+ messages << self
end
+ end
- # messages.each { |i| growl.notify $0, 'g', i, $g_priority, $g_sticky }
- messages.each { |i| GNTP.notify :app_name => $0, :title => 'g', :text => i, :sticky => $g_sticky }
+ messages.each do |i|
+ text = i.is_a?(String) ? i : i.pretty_inspect
+ GNTP.notify :app_name => $0, :title => 'g', :text => text, :sticky => $g_sticky
+ end
if args.empty?
- nil
+ self
elsif args.size == 1
args.first
else
View
24 spec/g_spec.rb
@@ -3,24 +3,24 @@
describe 'g' do
it 'calls with a arg' do
- GNTP.should_receive(:notify).with(:app_name => $0, :title => "g", :text => "foo".pretty_inspect, :sticky=>true)
+ GNTP.should_receive(:notify).with(:app_name => $0, :title => "g", :text => "foo", :sticky=>true)
g('foo').should == 'foo'
end
- it 'calls with block' do
- block = Proc.new {}
- GNTP.should_receive(:notify).with(:app_name => $0, :title => "g", :text => block.pretty_inspect, :sticky=>true)
- g(&block).should == block
+ it 'calls with args' do
+ GNTP.should_receive(:notify).exactly(2).times
+ g('foo', 1).should == ['foo', 1]
end
- it 'calls with args' do
- block = Proc.new {}
- GNTP.should_receive(:notify).exactly(3).times
- g('foo', 1, &block).should == ['foo', 1, block]
+ it 'calls for instance' do
+ object = Object.new
+ GNTP.should_receive(:notify).with(:app_name => $0, :title => "g", :text => object.pretty_inspect, :sticky=>true)
+ object.g.should == object
end
- it 'calls without args' do
- GNTP.should_receive(:notify).with(:app_name => $0, :title => "g", :text => "g!", :sticky=>true)
- g.should == nil
+ it 'calls with &block' do
+ object = "foo"
+ GNTP.should_receive(:notify).with(:app_name => $0, :title => "g", :text => "FOO", :sticky=>true)
+ object.g {|i| i.upcase}.should == object
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.