Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Created February 12, 2013 18:35
Show Gist options
  • Save nixpulvis/4772101 to your computer and use it in GitHub Desktop.
Save nixpulvis/4772101 to your computer and use it in GitHub Desktop.
The worst 3 line I've ever written, that also works.
s = options[:sudo].nil? ? sudo? || dependency.sudo? : options[:sudo]
f = options[:flags].nil? ? "#{flags+' ' if flags}#{dependency.flags}" : options[:flags]
system "#{'sudo ' if s}#{program} #{command} #{f+' ' unless f.to_s == ''}#{dependency}"
@ali
Copy link

ali commented Feb 12, 2013

Try this:

s = options[:sudo] || sudo? || dependency.sudo?
f = options[:flags] || "#{flags+' ' if flags}#{dependency.flags}"

@nixpulvis
Copy link
Author

nixpulvis commented Feb 13, 2013

That is not equivalent. Imagine this case:

options[:sudo] = false
sudo? = true
dependency.sudo? = true

You would say s == true but it shouldn't. I want options[:sudo] to have a higher precedence then anything else.

Keep in mind false.nil? == false

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