From 22be559374483d02255c09a77f91d0bb7f997553 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Thu, 27 Feb 2014 12:23:06 +0100 Subject: [PATCH] Fixed annoying Enumerable issue - now we can drop use of to_a in Ruby 1.9+ --- README.md | 2 +- lib/bio-table/filter.rb | 16 ++++++++++++---- lib/bio-table/statistics.rb | 7 ++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ada5e86..779489a 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ gem gem install statsample ``` -(statsample is not loaded by default, as it has a host of +(statsample is not loaded by default because it has a host of dependencies) Thereafter, to calculate the stats for columns 1 and 2 (rowname is column 0) diff --git a/lib/bio-table/filter.rb b/lib/bio-table/filter.rb index 1802818..5d89469 100644 --- a/lib/bio-table/filter.rb +++ b/lib/bio-table/filter.rb @@ -1,6 +1,10 @@ module BioTable + # LazyValues fetches values on demand from the @fields array. In the [] method + # a field is transformed into a float when it is called. + class LazyValues + include Enumerable def initialize fields @@ -16,12 +20,16 @@ def [] index @values[index] end - def each - @fields.each_with_index do | field, i | - yield self[i] + def each &block + @fields.each_with_index do |field,i| + if block_given? + block.call self[i] + else + yield self[i] + end end end - + def compact a = [] each do | e | diff --git a/lib/bio-table/statistics.rb b/lib/bio-table/statistics.rb index 6925dba..9288dcf 100644 --- a/lib/bio-table/statistics.rb +++ b/lib/bio-table/statistics.rb @@ -3,7 +3,12 @@ module BioTable module Statistics -require 'statsample' +begin + require 'statsample' +rescue LoadError + $stderr.print "Error: Missing statsample. Install with command 'gem install statsample'\n" + exit 1 +end attr_reader :columns