Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@caius
Created December 28, 2011 17:26
Show Gist options
  • Star 51 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save caius/1528785 to your computer and use it in GitHub Desktop.
Save caius/1528785 to your computer and use it in GitHub Desktop.
def output name=((default=true); "caius")
puts "name: #{name.inspect}"
puts "default: #{default.inspect}"
end
output
# >> name: "caius"
# >> default: true
output "avdi"
# >> name: "avdi"
# >> default: nil
@ngauthier
Copy link

also

def x(y=(raise 'i <3 params')); y; end

@skanev
Copy link

skanev commented Dec 29, 2011

Don't forget:

def foo(something = (def foo(*); 'bar'; end)) 'qux' end

puts foo(10)  # qux
puts foo      # qux
puts foo(10)  # bar
puts foo      # bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment