Skip to content

Instantly share code, notes, and snippets.

@moonpolysoft
Created May 5, 2009 20:37
Show Gist options
  • Save moonpolysoft/107183 to your computer and use it in GitHub Desktop.
Save moonpolysoft/107183 to your computer and use it in GitHub Desktop.
class Object
class Bypass
instance_methods.each do |m|
undef_method m unless m =~ /^__/
end
def initialize(ref)
@ref = ref
end
def method_missing(sym, *args)
@ref.__send__(sym, *args)
end
end
class Assigns
instance_methods.each do |m|
undef_method m unless m =~ /^__/
end
def initialize(ref)
@ref = ref
end
def method_missing(sym, *args)
if sym.to_s =~ /^(.+)=$/
@ref.instance_variable_set("@#{$1}", args.length == 1 ? args.first : args)
else
@ref.instance_variable_get("@#{sym}")
end
end
end
def bypass
Bypass.new(self)
end
def assigns
Assigns.new(self)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment