Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Silencing warnings.

  • Loading branch information...
commit a134c52ef3e55e9556cfdcee9597b6e0140b0fc5 1 parent 5f3c7d5
@JEG2 authored
Showing with 37 additions and 4 deletions.
  1. +4 −4 highline.gemspec
  2. +33 −0 lib/highline/string_extensions.rb
View
8 highline.gemspec
@@ -1,6 +1,6 @@
-DIR = File.dirname(__FILE__)
-LIB = File.join(DIR, *%w[lib highline.rb])
-VERSION = open(LIB) { |lib|
+DIR = File.dirname(__FILE__)
+LIB = File.join(DIR, *%w[lib highline.rb])
+GEM_VERSION = open(LIB) { |lib|
lib.each { |line|
if v = line[/^\s*VERSION\s*=\s*(['"])(\d+\.\d+\.\d+)\1/, 2]
break v
@@ -10,7 +10,7 @@ VERSION = open(LIB) { |lib|
SPEC = Gem::Specification.new do |spec|
spec.name = "highline"
- spec.version = VERSION
+ spec.version = GEM_VERSION
spec.platform = Gem::Platform::RUBY
spec.summary = "HighLine is a high-level command-line IO library."
spec.files = `git ls-files`.split("\n")
View
33 lib/highline/string_extensions.rb
@@ -32,17 +32,29 @@ module StringExtensions
def self.included(base)
HighLine::COLORS.each do |color|
base.class_eval <<-END
+ if public_instance_methods.map { |m| m.to_s }.
+ include? "#{color.downcase}"
+ undef :#{color.downcase}
+ end
def #{color.downcase}
color(:#{color.downcase})
end
END
base.class_eval <<-END
+ if public_instance_methods.map { |m| m.to_s }.
+ include? "on_#{color.downcase}"
+ undef :on_#{color.downcase}
+ end
def on_#{color.downcase}
on(:#{color.downcase})
end
END
HighLine::STYLES.each do |style|
base.class_eval <<-END
+ if public_instance_methods.map { |m| m.to_s }.
+ include? "#{style.downcase}"
+ undef :#{style.downcase}
+ end
def #{style.downcase}
color(:#{style.downcase})
end
@@ -51,31 +63,52 @@ def #{style.downcase}
end
base.class_eval do
+ if public_instance_methods.map { |m| m.to_s }.include? "color"
+ undef :color
+ end
+ if public_instance_methods.map { |m| m.to_s }.include? "foreground"
+ undef :foreground
+ end
def color(*args)
self.class.new(HighLine.color(self, *args))
end
alias_method :foreground, :color
+ if public_instance_methods.map { |m| m.to_s }.include? "on"
+ undef :on
+ end
def on(arg)
color(('on_' + arg.to_s).to_sym)
end
+ if public_instance_methods.map { |m| m.to_s }.include? "uncolor"
+ undef :uncolor
+ end
def uncolor
self.class.new(HighLine.uncolor(self))
end
+ if public_instance_methods.map { |m| m.to_s }.include? "rgb"
+ undef :rgb
+ end
def rgb(*colors)
color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
color("rgb_#{color_code}".to_sym)
end
+ if public_instance_methods.map { |m| m.to_s }.include? "on_rgb"
+ undef :on_rgb
+ end
def on_rgb(*colors)
color_code = colors.map{|color| color.is_a?(Numeric) ? '%02x'%color : color.to_s}.join
raise "Bad RGB color #{colors.inspect}" unless color_code =~ /^[a-fA-F0-9]{6}/
color("on_rgb_#{color_code}".to_sym)
end
+ if public_instance_methods.map { |m| m.to_s }.include? "method_missing"
+ undef :method_missing
+ end
# TODO Chain existing method_missing
def method_missing(method, *args, &blk)
if method.to_s =~ /^(on_)?rgb_([0-9a-fA-F]{6})$/
Please sign in to comment.
Something went wrong with that request. Please try again.