Revisions
-
technicalpickles revised this gist
Apr 6, 2009 . 1 changed file with 30 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,11 +16,34 @@ def respond_to?(sym, include_private = false) end end class NegativeFilterableEnumerable def initialize(original) @original = original end def ==(value) @original.select { |v| v != value } end def method_missing(sym, *args, &block) @original.select {|v| ! v.send(sym, *args, &block) } end def respond_to?(sym, include_private = false) @original.all? {|v| v.respond_to?(sym, include_private) } end end module Enumerable def filter FilterableEnumerable.new(self) end def filter_not NegativeFilterableEnumerable.new(self) end end @@ -50,16 +73,20 @@ def test_eq assert_equal [5], @array.filter == 5 end def test_not_eq assert_equal [0, 1, 2, 3, 4, 6, 7, 8, 9, 10], @array.filter_not == 5 end def test_method_missing assert_equal [0], @array.filter.zero? end def test_not_method_missing assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], @array.filter_not.zero? end def test_respond_to assert @array.filter.respond_to?(:zero?) end end -
jqr revised this gist
Apr 3, 2009 . 1 changed file with 0 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,14 +18,6 @@ def respond_to?(sym, include_private = false) end module Enumerable def filter FilterableEnumerable.new(self) end -
jqr revised this gist
Apr 3, 2009 . 1 changed file with 13 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,34 +3,18 @@ def initialize(original) @original = original end def ==(value) @original.select { |v| v == value } end def method_missing(sym, *args, &block) @original.select {|v| v.send(sym, *args, &block) } end def respond_to?(sym, include_private = false) @original.all? {|v| v.respond_to?(sym, include_private) } end end module Enumerable @@ -53,37 +37,37 @@ class TestFilterableEnumerable < Test::Unit::TestCase def setup @array = (0..10).to_a end def test_gte assert_equal [5, 6, 7, 8, 9, 10], @array.filter >= 5 end def test_gt assert_equal [6, 7, 8, 9, 10], @array.filter > 5 end def test_lte assert_equal [0, 1, 2, 3, 4], @array.filter < 5 end def test_le assert_equal [0, 1, 2, 3, 4, 5], @array.filter <= 5 end def test_eq assert_equal [5], @array.filter == 5 end def test_neq assert_equal [0, 1, 2, 3, 4, 6, 7, 8, 10], @array.filter != 5 end def test_method_missing assert_equal [0], @array.filter.zero? end def test_respond_to assert @array.filter.respond_to?(:zero?) end end -
technicalpickles revised this gist
Apr 2, 2009 . 1 changed file with 53 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,29 +6,38 @@ def initialize(original) def >(value) @original.select { |v| v > value } end def >=(value) @original.select { |v| v >= value } end def <(value) @original.select { |v| v < value } end def <=(value) @original.select { |v| v <= value } end def ==(value) @original.select { |v| v == value } end def method_missing(sym, *args, &block) @original.select {|v| v.send(sym, *args, &block) } end def respond_to?(sym, include_private = false) @original.all? {|v| v.respond_to?(sym, include_private) } end end module Enumerable def >(value) select { |v| v > value } end def <(value) select { |v| v < value } end @@ -37,14 +46,44 @@ def filter FilterableEnumerable.new(self) end end require 'test/unit' class TestFilterableEnumerable < Test::Unit::TestCase def setup @array = (0..10).to_a end def test_gte assert_equal [5, 6, 7, 8, 9, 10], @array.filter >= 5 end def test_gt assert_equal [6, 7, 8, 9, 10], @array.filter > 5 end def test_lte assert_equal [0, 1, 2, 3, 4], @array.filter < 5 end def test_le assert_equal [0, 1, 2, 3, 4, 5], @array.filter <= 5 end def test_eq assert_equal [5], @array.filter == 5 end def test_neq assert_equal [0, 1, 2, 3, 4, 6, 7, 8, 10], @array.filter != 5 end def test_method_missing assert_equal [0], @array.filter.zero? end def test_respond_to assert @array.filter.respond_to?(:zero?) end end -
jqr revised this gist
Apr 2, 2009 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,3 +45,6 @@ def filter a.filter < 5 # => [1, 2, 3, 4] a.filter <= 5 # => [1, 2, 3, 4, 5] a.filter == 5 # => [5] # and the problem case: a.filter != 5 # => false -
jqr revised this gist
Apr 2, 2009 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,18 @@ def >(value) @original.select { |v| v > value } end def >=(value) @original.select { |v| v >= value } end def <(value) @original.select { |v| v < value } end def <=(value) @original.select { |v| v <= value } end def ==(value) @original.select { |v| v == value } end @@ -28,11 +36,12 @@ def <(value) def filter FilterableEnumerable.new(self) end end a = (1..10).to_a a.filter >= 5 # => [5, 6, 7, 8, 9, 10] a.filter > 5 # => [6, 7, 8, 9, 10] a.filter < 5 # => [1, 2, 3, 4] a.filter <= 5 # => [1, 2, 3, 4, 5] a.filter == 5 # => [5] -
jqr revised this gist
Apr 2, 2009 . 1 changed file with 26 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,21 @@ class FilterableEnumerable def initialize(original) @original = original end def >(value) @original.select { |v| v > value } end def <(value) @original.select { |v| v < value } end def ==(value) @original.select { |v| v == value } end end module Enumerable def >(value) select { |v| v > value } @@ -7,8 +24,15 @@ def >(value) def <(value) select { |v| v < value } end def filter FilterableEnumerable.new(self) end end a = (1..10).to_a a.filter > 5 # => [6, 7, 8, 9, 10] a.filter < 5 # => [1, 2, 3, 4] a.filter == 5 # => [5] -
jqr created this gist
Apr 2, 2009 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ # Yes this is a terrible idea, but we're just getting started... module Enumerable def >(value) select { |v| v > value } end def <(value) select { |v| v < value } end end a = (1..10).to_a a > 5 # => [6, 7, 8, 9, 10]