Last active
November 24, 2015 02:27
-
-
Save goyusia/8769a4132b36dea6e4e6 to your computer and use it in GitHub Desktop.
function default value (Python vs Ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| ''' | |
| [haruna@haruna test ]$ ./function_default_value_python.py | |
| 2015-11-24 11:16:47.815578 | |
| 2015-11-24 11:16:47.815578 | |
| same | |
| ''' | |
| import time | |
| import datetime | |
| def print_now(now = datetime.datetime.now()): | |
| print(now) | |
| print_now() | |
| time.sleep(5) | |
| print_now() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| =begin | |
| [haruna@haruna test ]$ ./function_default_value_ruby.rb | |
| 2015-11-24 11:17:20 +0900 | |
| 2015-11-24 11:17:25 +0900 | |
| not same | |
| =end | |
| def print_now(now = Time.now()) | |
| puts now | |
| end | |
| print_now | |
| sleep 5 | |
| print_now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment