23 Dec '13, 10am

Good practices that any #ruby developer should never forget when #coding. Tell, Don't Ask

Ben Orenstein July 19, 2012 ruby And now, a friendly message from your local Tell, don't ask Department. Example 1 Not so good: <% if current_user.admin? %> <%= current_user.admin_welcome_message %> <% else %> <%= current_user.user_welcome_message %> <% end %> Better: <%= current_user.welcome_message %> Example 2 Not so good: def check_for_overheating(system_monitor) if system_monitor.temperature > 100 system_monitor.sound_alarms end end Better: system_monitor.check_for_overheating class SystemMonitor def check_for_overheating if temperature > 100 sound_alarms end end end Example 3 Not so good: class Post def send_to_feed if user.is_a?(TwitterUser) user.send_to_feed(contents) end end end Better: class Post def send_to_feed user.send_to_feed(contents) end end class TwitterUser def send_to_feed(contents) twitter_client.post_to_feed(contents) end end class EmailUser def send_...

Full article: http://robots.thoughtbot.com/tell-dont-ask

Tweets

You asked, I answered: #askmish

michellephan.com 23 Dec '13, 7pm

In between my gift wrapping video and my upcoming New Year’s tutorial, I decided to take time to answer some of the questi...

Tell us if you're feeling this "Red Python" Air...

twitter.com 24 Dec '13, 6am

To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content,...

Just don't ask for your benefits.. #MorningJoe ...

twitter.com 30 Dec '13, 1pm

To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content,...

Check out FT Island's Shoutout for their FTHX C...

youtube.com 26 Dec '13, 4am

Unfortunately, this video is not available in Germany because it may contain music for which GEMA has not granted the resp...

Sink tank: In Miami, climate scientists ask, “How deep, how soon?”

Sink tank: In Miami, climate scientists ask, “H...

grist.org 18 Dec '13, 12pm

Harold “Hal” Wanless is a wizened walrus of a man who presides over the University of Miami’s geology department from a fl...