15 Aug '13, 7am

Renderable Null Objects

August 15, 2013 georgebrock null object refactoring rails We’ve talked about Null Objects before , and how they can remove unwanted conditionals from your code. I’d like to talk about extending those benefits into your Rails views. Setting the scene Recently I’ve been working on an application that displays a lot of graphs of financial data. A DataSeries can return a graph of its recent history, but only if it has_data? . # app/models/users/data_series.rb class DataSeries < ActiveRecord::Base def recent_history_graph if has_data? Graph.new(self) end end def has_data? # ... end end In the view, the graph is rendered like this: # app/views/data_series/show.html.erb <% if @data_series.recent_history_graph %> <%= render @data_series.recent_history_graph %> <% end %> This code isn’t too bad, but it could be better. The has_data? check is already happening inside the recent_hist...

Full article: http://robots.thoughtbot.com/post/58313551647/renderable-...

Tweets

Secretly Tag 3-D-Printed Objects With InfraStructs

spectrum.ieee.org 20 Aug '13, 2pm

Ever wanted to send secret information just by passing along an ordinary-looking object? That’s the premise of Microsoft R...

thoughtbot news: Build Phase Episode 3: Create ...

robots.thoughtbot.com 14 Aug '13, 2pm

giant robots smashing into other giant robots Written by thoughtbot Build Phase Episode 3: Create All The Objects! August ...