Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
def required(arg=nil)
method = caller_locations(1,1)[0].label
raise ArgumentError.new("required parameter #{arg.to_sym.inspect + ' ' if arg}not passed to method #{method}")
end
def say(greeting: required('greeting'))
puts greeting
end
def say2(greeting: required)
puts greeting
end
def say3(greeting: required(:greeting))
puts greeting
end
# say
# test.rb:3:in `required': required parameter :greeting not passed to method say (ArgumentError)
# from test.rb:6:in `say'
# from test.rb:18:in `<main>'
# say2
# test.rb:3:in `required': required parameter not passed to method say2 (ArgumentError)
# from test.rb:10:in `say2'
# from test.rb:23:in `<main>'
# say3
#test.rb:3:in `required': required parameter :greeting not passed to method say3 (ArgumentError)
# from test.rb:14:in `say3'
# from test.rb:28:in `<main>'
# calling it like say('greeting') results in ArgumentError
say greeting: 'greeting'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.