So I thought I was being clever, writing my Rails controller actions like this:
def create
set_post_from_post_id
set_comment_as_new
respond_to do |format|
comment.save| require 'benchmark' | |
| class MyClassWithStuff | |
| DEFAULT_VALS = { one: '1' } | |
| def memoized_fetch | |
| @value ||= DEFAULT_VALS[:one] | |
| end |
| # Bad: | |
| class OrdersController | |
| exposes :orders | |
| def index | |
| @orders = Order.complete | |
| end | |
| def pending |
| class OrdersController | |
| def index | |
| end | |
| def pending | |
| end | |
| private | |
| class Array | |
| # Inserts an object to the Array if condition is true | |
| # | |
| # object - The object to insert. | |
| # condition - The condition to evaluate. | |
| # | |
| # Example: | |
| # | |
| # = content_tag(:div, class: ["user-username"].insert_if("active", @user.active)) do |
| [diff] | |
| tool = diff | |
| algorythm = minimal | |
| [color] | |
| branch = auto | |
| diff = auto | |
| status = auto | |
| interactive = auto | |
| ui = true | |
| pager = true |
| #import <AddressBook/AddressBook.h> | |
| #import <Accounts/Accounts.h> | |
| #import <Social/Social.h> | |
| @interface ContactsDiscovery() | |
| @property (nonatomic, retain) ACAccountStore* accounts; | |
| @property (nonatomic, retain) ACAccountType* faceBookAccountType; | |
| @property (nonatomic, retain) ACAccount* faceBookAccount; | |
| @property (nonatomic, retain) id addressBook; | |
| @end |
| require 'time' | |
| require 'date' | |
| class Invitee | |
| end | |
| class Event | |
| attr_accessor :name | |
| attr_accessor :date | |
| attr_accessor :starts_at |
| def should_nest_multiple_conditionals? | |
| x = rand(10).to_i | |
| if Time.now.strftime("%A") != "Friday" | |
| if current_client.is_large_faceless_conglomerate? | |
| return true | |
| elsif Time.now.strftime("%A") == "Friday" | |
| return true | |
| end | |
| elsif LocalWeather.new("Edinburgh").sunny? |
| require 'benchmark' | |
| TIMES = 1000000 | |
| STRING = "this is a long and bad-ass string" | |
| Benchmark.bmbm do |test| | |
| test.report("Index") do | |
| TIMES.times { STRING.index("this is") } |