Created
May 21, 2011 21:46
-
-
Save justinko/984927 to your computer and use it in GitHub Desktop.
A simple delegate to an array
This file contains 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 characters
require 'forwardable' | |
class BenArray | |
extend Forwardable | |
def initialize | |
@array = [] | |
end | |
def_delegators :@array, :select, :reject, :<< | |
def a | |
select {|i| i < 4} | |
end | |
def b | |
reject {|i| i > 2} | |
end | |
end | |
ba = BenArray.new | |
ba << 5 | |
ba << 4 | |
ba << 3 | |
ba << 2 | |
ba << 1 | |
puts ba.a.b.join(" ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment