Skip to content

Instantly share code, notes, and snippets.

@xn
Created September 4, 2013 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xn/6437855 to your computer and use it in GitHub Desktop.
Save xn/6437855 to your computer and use it in GitHub Desktop.
gem idea
require 'forwardable'
module Blah
include ::Forwardable
def self.extended(base)
base.send :def_delegators, :@list, :<<, :length # and anything else
end
end
class List
extend Blah
def initialize(list = [])
@list = list
end
def reverse
List.new(@list.reverse)
end
end
l = List.new
l << 1
l << 2
puts l.reverse.class # => List
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment