Created
September 4, 2013 14:38
-
-
Save xn/6437855 to your computer and use it in GitHub Desktop.
gem idea
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' | |
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