Skip to content

Instantly share code, notes, and snippets.

@ipmsteven
Created September 23, 2014 17:09
Show Gist options
  • Select an option

  • Save ipmsteven/5312672181493315910d to your computer and use it in GitHub Desktop.

Select an option

Save ipmsteven/5312672181493315910d to your computer and use it in GitHub Desktop.
undef in ruby
class SimpleProxy
instance_methods.each do |m|
unless m.to_s =~ /^(?:nil\?|send|object_id|to_a|tap)$|^__|^respond_to|instance_variable_get/
undef_method m
end
end
def initialize(object)
@object = object
end
def is_a?(klass)
super || @object.is_a?(klass)
end
def as_a(klass)
if @object.is_a?(klass)
return @object
end
raise
end
end
simple_proxy = SimpleProxy.new("hello")
puts simple_proxy.is_a? SimpleProxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment