Skip to content

Instantly share code, notes, and snippets.

@masonforest
Created October 12, 2012 23:06
Show Gist options
  • Save masonforest/3882144 to your computer and use it in GitHub Desktop.
Save masonforest/3882144 to your computer and use it in GitHub Desktop.
Connascence of Position (CoP) Problem - Fixed with named parameters in Ruby 2.0
=begin
Our "Connascence of Position" problem can be solved with named parameters available in Ruby 2.0
=end
def do_things(puppie_count: 0, missle_count: 0)
puts "Played with #{puppie_count} puppies"
puts "Launched #{missle_count} missles"
end
puts "Everything is Fine"
do_things(puppie_count: 5, missle_count:0)
do_things(puppie_count: 10, missle_count:0)
do_things(puppie_count: 12, missle_count:0)
do_things(missle_count: 0, puppie_count: 12)
puts "Everything is okay!
=begin
Output:
Everything is Fine
Played with 5 puppies
Launched 0 missles
Played with 10 puppies
Launched 0 missles
Played with 12 puppies
Launched 0 missles
Played with 12 puppies
Launched 0 missles
Everything is okay!
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment