Skip to content

Instantly share code, notes, and snippets.

@tie-rack
Created June 4, 2009 19:55
Show Gist options
  • Save tie-rack/123808 to your computer and use it in GitHub Desktop.
Save tie-rack/123808 to your computer and use it in GitHub Desktop.
class BlankSlate
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
end
class Delegated < BlankSlate
attr_reader :delegate
def initialize(delegate)
@delegate = delegate
end
def method_missing(name, *args, &block)
@delegate.send(name, *args, &block)
end
end
array = []
delegated = Delegated.new(array)
# MRI/YARV/JRuby # Rubinius
delegated.class # Array # Array
delegated.kind_of?(Array) # true # true
delegated.object_id # 80250 # 16
array.class # Array # Array
array.kind_of?(Array) # true # true
array.object_id # 80250 # 16
array == delegated # true # true
delegated == array # true # true
Array === delegated # false # true
Delegated === delegated # true # false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment