From e57559f8ae50b489dd5e239179e518d0834054da Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Thu, 16 Jul 2015 16:10:31 +0200 Subject: SparseVector: fixes --- lib/zipf/SparseVector.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/zipf/SparseVector.rb b/lib/zipf/SparseVector.rb index 976ecaf..456aeb2 100644 --- a/lib/zipf/SparseVector.rb +++ b/lib/zipf/SparseVector.rb @@ -7,6 +7,10 @@ class SparseVector < Hash self.default = 0 if arg.is_a? Array from_a arg + elsif arg.is_a? Hash + from_h arg + elsif arg.is_a? String + from_s arg end end @@ -212,7 +216,9 @@ class SparseVector < Hash end def unit - return SparseVector.new(self).unit! + v = SparseVector.new(self) + v.unit! + return v end end -- cgit v1.2.3