20 Dec '13, 5pm

Clearer Conditionals using De Morgan's Laws

Clearer Conditionals using De Morgan's Laws Gabe Berke-Williams December 20, 2013 refactoring Ever seen a hard-to-parse conditional like this? def allow_access_to_site? ! (signed_out? && untrusted_ip?) end Let's use De Morgan's Laws to clean it up and see who actually has access to our site. De Morgan's Laws Whoa, who's this De Morgan guy? Augustus De Morgan , in addition to looking like a 19th-century John C. Reilly , formulated two important rules of logical inference. You can check out the formal definition on the Wikipedia page , but here they are in Ruby code: # One !(a && b) == !a || !b # Two !(a || b) == !a && !b Well hey, it looks like we can use these on our gnarly conditional above. Let's try it. Law-abiding Ruby code Recall that the original conditional was ! (signed_out? && untrusted_ip?) . Let's use the second law and puzzle it out. # Original ! (signed_out? &...

Full article: http://robots.thoughtbot.com/clearer-conditionals-using-d...

Tweets

Clearer Conditionals using De Morgan's Laws

robots.thoughtbot.com 21 Dec '13, 11pm

Clearer Conditionals using De Morgan's Laws Gabe Berke-Williams December 20, 2013 refactoring Ever seen a hard-to-parse co...

How to Extract an Intention-Revealing Name Usin...

robots.thoughtbot.com 21 Dec '13, 4pm

How to Extract an Intention-Revealing Name Using Vim Joe Ferris May 02, 2012 vim refactoring This method has a magic numbe...

[Princessa's Diary] My Journey to Clearer Vision (Part 2)

[Princessa's Diary] My Journey to Clearer Visio...

sabrina.sg 21 Dec '13, 2am

Do you remember my story with astigmatism from my last post ? Well, let me share the embarrassing situations that my uncor...

@Nytyr @JoseiRS @chrbongardt "Ruby es... Un len...

ruby-lang.org 20 Dec '13, 12pm

Un lenguaje de programación dinámico y de código abierto enfocado en la simplicidad y productividad. Su elegante sintaxis ...

Using 'index_exists?' check before adding index...

apidock.com 19 Dec '13, 5am

Checks to see if an index exists on a table for a given index definition. Examples # Check an index exists index_exists? (...

Jon Bernthal Joins HSUS to Enforce Animal Cruelty Laws | Ecorazzi

Jon Bernthal Joins HSUS to Enforce Animal Cruel...

ecorazzi.com 20 Dec '13, 1pm

“Countless dogs, cats and other animals fall victim to unnecessary cruelty and neglect. Every state has laws prohibiting a...

I have the pleasure of contributing to @luxury_...

aluxurytravelblog.com 20 Dec '13, 7am

Share romantic nights under the stars with that special someone, in the quaint, romantic village of Saint Paul de Vence, w...