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
# Weird ruby behavior | |
>> class Foo; end | |
=> nil | |
>> defined?(Foo) | |
=> "constant" | |
>> defined?("Foo".constantize) | |
=> "method" | |
# |
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
# When you have duplication like this | |
def base_price(options = {}) | |
PriceFormatter::Formatter.format(super, options) | |
end | |
def price(options = {}) | |
PriceFormatter::Formatter.format(base_price * quantity, options) | |
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
def sample_file(name = "most_used_file.png") | |
File.new("test/fixtures/files/#{name}") | |
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
# Rake tasks for managing git plugins with submodules. | |
# | |
# These tasks aim to make life simpler by automating all the boring work. | |
# What you get: | |
# - complete git integration (all you need to know is install, uninstall and update) | |
# - complete github integration (only use author name + plugin name) | |
# - rails plugin hooks (install.rb/uninstall.rb) are taken care of | |
# | |
# Available commands: | |
# |
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
# Install | |
# | |
# Move this file into config/preinitializer.rb | |
# | |
# Usage | |
# | |
# This line: | |
# config.github_gem "mislav-will_paginate" | |
# is equivalent to this line: | |
# config.gem "mislav-will_paginate", :lib => "will_paginate", :source => "http://gem.github.com" |
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 has_role?(role, object) | |
if object.has_association?(role) | |
if has_many? | |
object.roles.find(self.id) | |
else | |
object.role.id == self.id | |
end | |
else | |
self.roles.include?(role) | |
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
context "with associations" do | |
setup do | |
fake_association = Struct.new(:macro, :name, :object) | |
fake_object_with_associations = Struct.new(:associations) do | |
def reflect_on_all_associations | |
associations | |
end | |
def method_missing(meth, *args, &blk) | |
association = associations.find{|a| a.name == meth} |
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
context "with associations" do | |
setup do | |
fake_association = Struct.new(:macro, :name, :object) | |
klass_with_associations = proc{|associations| | |
Class.new do | |
self.class.send(:define_method, :reflect_on_all_associations) do | |
associations | |
end | |
define_method(:method_missing) do |meth| |
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 title(page_title, show_title = true) | |
content_for(:title) { t('.title', :default => page_title) } | |
@show_title = show_title | |
end | |
def show_title? | |
@show_title | |
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
projects/lab/freight[devise]% sudo gem update rr | |
Password: | |
Updating installed gems | |
Updating acts_as_ferret | |
Successfully installed acts_as_ferret-0.4.4 | |
Gems updated: acts_as_ferret | |
Installing RDoc documentation for acts_as_ferret-0.4.4... |