Skip to content

Instantly share code, notes, and snippets.

@nateklaiber
Forked from alisdair/invisible_proxy.rb
Last active August 29, 2015 14:19
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 nateklaiber/d86ec65de7fff4975831 to your computer and use it in GitHub Desktop.
Save nateklaiber/d86ec65de7fff4975831 to your computer and use it in GitHub Desktop.
class FlatArray
instance_methods.each do |m|
undef_method(m) unless m =~ /(^__|^nil\?|^send$|^object_id$)/
end
def initialize(array)
@target = array
end
def respond_to?(symbol, include_priv=false)
@target.respond_to?(symbol, include_priv)
end
def <<(object)
if object.is_a? Array
@target += object
else
@target << object
end
end
private
def method_missing(method, *args, &block)
@target.send(method, *args, &block)
end
end
a = [1, 2, 3, 4]
puts "a.class = #{a.class}"
puts "a = #{a.inspect}"
a << [5, 6, 7]
puts "a = #{a.inspect}"
b = FlatArray.new([1, 2, 3, 4])
puts "b.class = #{b.class}"
puts "b = #{b.inspect}"
b << [5, 6, 7]
puts "b = #{b.inspect}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment