Created
November 2, 2015 17:24
-
-
Save olistik/8cb55815197f9a43118d to your computer and use it in GitHub Desktop.
Prevents raised exceptions to be computationally expensive. Reference: https://gist.github.com/olistik/46a0b2879d6b5e7f616a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
def index | |
foo_data.foo1 | |
foo_data.foo2 | |
request.xxx | |
end | |
private | |
def foo_data | |
@foo_data ||= foo_data | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def initialize(name) | |
@name = name | |
log(:initialize) | |
end | |
def inspect | |
log(:inspect) | |
end | |
def to_s | |
log(:to_s) | |
end | |
def log(context) | |
Rails.logger.debug "XXX Foo(#{@name}).#{context}" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooData | |
def inspect | |
"this is a cheap string" | |
end | |
def foo1 | |
@foo1 ||= Foo.new(:foo1) | |
end | |
def foo2 | |
@foo2 ||= Foo.new(:foo2) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment