Skip to content

Instantly share code, notes, and snippets.

@mumumu
Last active December 16, 2015 16:49
Show Gist options
  • Save mumumu/5465691 to your computer and use it in GitHub Desktop.
Save mumumu/5465691 to your computer and use it in GitHub Desktop.
difference of keyword arguments between Ruby 2.0.0 and Python.
mumumu@www 17:12:11$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def test(a = []):
... a.append(10)
... print a
...
>>> test()
[10]
>>> test()
[10, 10]
>>> test()
[10, 10, 10]
>>> test()
[10, 10, 10, 10]
----
mumumu@www 17:11:26$ ruby --version
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
mumumu@www 17:11:35$ irb
irb(main):001:0> def test(a = [])
irb(main):002:1> a.push(10)
irb(main):003:1> end
=> nil
irb(main):004:0> test
=> [10]
irb(main):005:0> test
=> [10]
irb(main):006:0> test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment