Skip to content

Instantly share code, notes, and snippets.

@fcamel
Created April 23, 2017 01:25
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 fcamel/a1d0f1bfcf7672ee162edab3464fd8ae to your computer and use it in GitHub Desktop.
Save fcamel/a1d0f1bfcf7672ee162edab3464fd8ae to your computer and use it in GitHub Desktop.
ruby, python, comparison of redefining class
$ cat a.py
class A(object):
def foo(self):
return "foo"
a = A()
print a.foo()
class A(object):
def foo(self):
return "bar"
print a.foo()
$ python a.py
foo
foo
$ cat a.rb
class A
def foo
return "foo"
end
end
a = A.new
print a.foo(), "\n"
class A
def foo
return "bar"
end
end
print a.foo(), "\n"
$ ruby a.rb
foo
bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment