colorb 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/colorb.rb +13 -11
  2. metadata +3 -3
@@ -51,7 +51,7 @@ class String
51
51
  def method_missing (id, *args, &block)
52
52
  name = id.to_s.match(/^(.+?)[!?]?$/)[1].to_sym
53
53
 
54
- result = self.frozen? ? "#{self}" : self
54
+ result = (self.frozen? || !id.to_s.end_with?('!')) ? self.clone : self
55
55
 
56
56
  return __old_method_missing(id, *args, &block) unless Colors[name] || Extra[name]
57
57
 
@@ -81,29 +81,31 @@ class String
81
81
  def color (code, second=nil)
82
82
  return method_missing(code.to_sym) if code.is_a?(Symbol) || code.is_a?(String)
83
83
 
84
- result = self.frozen? ? "#{self}" : self
84
+ self.clone.color!(code, seond)
85
+ end
85
86
 
87
+ def color! (code, second=nil)
86
88
  if code < 16
87
89
  if code > 7
88
- (result.flags ||= []) << (!result.foreground ? :bold : :blink)
90
+ (self.flags ||= []) << (!self.foreground ? :bold : :blink)
89
91
  end
90
92
 
91
- if !result.foreground
92
- result.foreground = code - (code > 7 ? 7 : 0)
93
+ if !self.foreground
94
+ self.foreground = code - (code > 7 ? 7 : 0)
93
95
  else
94
- result.background = code - (code > 7 ? 7 : 0)
96
+ self.background = code - (code > 7 ? 7 : 0)
95
97
  end
96
98
  else
97
- if !result.foreground
98
- result.foreground = code
99
+ if !self.foreground
100
+ self.foreground = code
99
101
  else
100
- result.background = code
102
+ self.background = code
101
103
  end
102
104
  end
103
105
 
104
- result.color(second) if second
106
+ self.color(second) if second
105
107
 
106
- result.lazy? ? result : result.colorify!
108
+ self.lazy? ? self : self.colorify!
107
109
  end
108
110
 
109
111
  def lazy; @lazy = true; self end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - meh.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-17 00:00:00 +01:00
17
+ date: 2011-02-04 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20