Skip to content

Instantly share code, notes, and snippets.

@sahglie
Created May 13, 2012 00:28
Show Gist options
  • Save sahglie/2669899 to your computer and use it in GitHub Desktop.
Save sahglie/2669899 to your computer and use it in GitHub Desktop.
Making ruby act like python
class TestObject
def method_missing(message, *args, &block)
if !self.respond_to?(message) && message[/=/]
self.class.send(:attr_accessor, message[0...-1])
self.send(message, args[0])
else
super
end
end
end
o = TestObject.new()
begin
x = o.bar()
puts x
rescue NoMethodError
puts "No method 'bar'"
end
o.bar = "array of objects"
x = o.bar()
puts x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment