Skip to content

Instantly share code, notes, and snippets.

@aitor
Forked from porras/wadus.rb
Created July 2, 2010 10:53
Show Gist options
  • Save aitor/461218 to your computer and use it in GitHub Desktop.
Save aitor/461218 to your computer and use it in GitHub Desktop.
def wadus(wadus = nil, options = {})
puts "wadus = #{wadus.inspect}"
puts "options = #{options.inspect}"
end
wadus
# wadus = nil
# options = {}
# OK
wadus "wadus"
# wadus = "wadus"
# options = {}
# OK
wadus "wadus", :wadus => "wadus"
# wadus = "wadus"
# options = {:wadus=>"wadus"}
# OK
wadus :wadus => "wadus"
# wadus = {:wadus=>"wadus"}
# options = {}
# Instead of what I wanted which is:
# wadus = nil
# options = {:wadus=>"wadus"}
# In Rails I've seen things like:
def jander(wadus = nil, options = {})
if wadus.is_a?(Hash)
options = wadus
wadus = nil
end
puts "wadus = #{wadus.inspect}"
puts "options = #{options.inspect}"
end
jander
# wadus = nil
# options = {}
# OK
jander "wadus"
# wadus = "wadus"
# options = {}
# OK
jander "wadus", :wadus => "wadus"
# wadus = "wadus"
# options = {:wadus=>"wadus"}
# OK
jander :wadus => "wadus"
# wadus = nil
# options = {:wadus=>"wadus"}
# OK
# But that's ugly man!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment