Permalink
Browse files

Ruby 1.8 compatibility

  • Loading branch information...
cespare committed May 11, 2011
1 parent fa95f41 commit f3946ea6e177920351a4296d69478125e47d6072
Showing with 6 additions and 5 deletions.
  1. +1 −1 discoball.gemspec
  2. +5 −4 lib/discoball.rb
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "discoball"
- s.version = "0.1.0"
+ s.version = "0.2.0"
s.required_rubygems_version = Gem::Requirement.new(">=0") if s.respond_to? :required_rubygems_version=
s.specification_version = 2 if s.respond_to? :specification_version=
View
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
+require "rubygems"
require "colorize"
module Discoball
@@ -33,10 +34,10 @@ def filter(line)
case @color_mode
when :one_color
- matches = @patterns.flat_map { |pattern|
+ matches = @patterns.reduce([]) { |memo, pattern| # No Array#flat_map in Ruby 1.8 :\
m = line.scan(pattern)
match_found[pattern] = true unless m.empty?
- m
+ memo += m
}.uniq
matches.each { |match| highlight!(line, match, SINGLE_COLOR) }
when :group_colors
@@ -46,10 +47,10 @@ def filter(line)
matches.each { |match| highlight!(line, match, @color_assignments[pattern]) }
end
when :individual
- matches = @patterns.flat_map { |pattern|
+ matches = @patterns.reduce([]) { |memo, pattern|
m = line.scan(pattern)
match_found[pattern] = true unless m.empty?
- m
+ memo += m
}.uniq
matches.each do |match|
unless @color_assignments.include? match

0 comments on commit f3946ea

Please sign in to comment.