Skip to content

Instantly share code, notes, and snippets.

@justinko
Created May 21, 2011 21:46
Show Gist options
  • Save justinko/984927 to your computer and use it in GitHub Desktop.
Save justinko/984927 to your computer and use it in GitHub Desktop.
A simple delegate to an array
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