- Ruby Delegate.rb Secrets
- Simple presenters to clean up views
- Ruby Forwardable in Depth
- how it works
- SingleForwardable
- identifying responsibility leaks with if
- enforcing encapsulation
- seeing the westward flow and heading east
- ActiveSupport::Delegation, the Rails approach to forwarding
- The Casting gem and why it's different from SimpleDelegator
This file contains 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
seed = [[0,0],[0,1],[0,2]] | |
puts "First generation:" | |
puts seed.to_s | |
# Point surrounding a given point | |
perimeter = ->(x, y){ | |
[ | |
[x - 1, y + 1], [x, y + 1], [x + 1, y + 1], | |
[x - 1, y ], [x + 1, y ], | |
[x - 1, y - 1], [x, y - 1], [x + 1, y - 1] |
This file contains 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
require 'delegate' | |
class SpecialFormatter < SimpleDelegator | |
def initialize(user, profile) | |
super(user) | |
@profile = profile | |
end | |
attr_reader :profile | |
def self.maybe(*names) |
This file contains 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
def custom_mail_to(email, link_text, i18n_subject_key) | |
mail_to(email, link_text, :subject => I18n.t(i18n_subject_key, :email => email)) | |
end |
This file contains 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 Something | |
setup(:first, :second) | |
module Second | |
end | |
end | |
# This is the equivalent of what the code above does... | |
class Something |
This file contains 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 Mapper | |
with_options :prefix => 'special_' do | |
property :id | |
property :name | |
property :other | |
end | |
end | |
# This would yield {"special_id" => 1, "special_name" => 'something', "special_other" => 'other value' } |
This file contains 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
brew install -v graphviz | |
==> Downloading http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.28.0.tar.gz | |
Already downloaded: /Library/Caches/Homebrew/graphviz-2.28.0.tar.gz | |
/usr/bin/tar xf /Library/Caches/Homebrew/graphviz-2.28.0.tar.gz | |
==> Downloading patches | |
/usr/bin/curl -f#LA Homebrew 0.9.3 (Ruby 1.8.7-358; Mac OS X 10.8.2) https://trac.macports.org/export/78507/trunk/dports/graphics/graphviz-gui/files/patch-project.pbxproj.diff -o 001-homebrew.diff | |
######################################################################## 100.0% | |
==> Patching | |
/usr/bin/patch -f -p1 -i 000-homebrew.diff | |
patching file lib/gvc/Makefile.in |
This file contains 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
# This is from a production application of mine | |
def ExpertTag(tag) | |
tag.is_a?(ExpertTag) ? tag : ExpertTag.new(tag) | |
end | |
class ExpertTag | |
def initialize(radius_tag) | |
@radius_tag = radius_tag | |
end |
This file contains 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
project_type = :rails | |
project_path = Compass::AppIntegration::Rails.root | |
http_path = "/" | |
http_stylesheets_path = "/stylesheets" | |
http_images_path = "/images" | |
http_javascripts_path = "/javascripts" | |
sass_dir = "public/stylesheets/sass" | |
css_dir = "tmp/public/stylesheets" |
This file contains 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
project_type = :rails | |
project_path = Compass::AppIntegration::Rails.root | |
http_path = "/" | |
http_stylesheets_path = "/stylesheets" | |
http_images_path = "/images" | |
http_javascripts_path = "/javascripts" | |
sass_dir = "public/stylesheets/sass" | |
css_dir = "tmp/public/stylesheets" |