Skip to content

Instantly share code, notes, and snippets.

@hseritt
Created June 1, 2019 03:10
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 hseritt/a8338a88e717d5ebf7baafc3f7b3ebc7 to your computer and use it in GitHub Desktop.
Save hseritt/a8338a88e717d5ebf7baafc3f7b3ebc7 to your computer and use it in GitHub Desktop.
If I run example.py, I get "8" ... if run example.rb I get error: Traceback (most recent call last): 1: from ./example1.rb:12:in `<main>' ./example1.rb:3:in `times2': wrong number of arguments (given 0, expected 1) (ArgumentError)
#!/usr/bin/env python
def times2(num):
return num * 2
def add(num1, num2, fn=None):
sum = num1 + num2
return fn(sum)
answer = add(1, 3, times2)
print(answer)
#!/usr/bin/env ruby
def times2(num)
return num * 2
end
def add(num1, num2, fn=nil)
sum = num1 + num2
return fn sum
end
answer = add(1, 3, times2)
puts answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment