Permalink
Browse files

Fixed annoying Enumerable issue - now we can drop use of to_a in Ruby…

… 1.9+
  • Loading branch information...
1 parent e8e5e45 commit 22be559374483d02255c09a77f91d0bb7f997553 @pjotrp committed Feb 27, 2014
Showing with 19 additions and 6 deletions.
  1. +1 −1 README.md
  2. +12 −4 lib/bio-table/filter.rb
  3. +6 −1 lib/bio-table/statistics.rb
View
@@ -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)
View
@@ -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 |
@@ -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

0 comments on commit 22be559

Please sign in to comment.