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 Test | |
%w{one two three}.each do |p| | |
define_method("#{p}?") { self.wat == p } | |
end | |
def wat | |
"two" | |
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
# Allows you to do (1) instead of (2) | |
# 1 | |
Given /^I sign up as a staff member with login "([^\"]*)"$/ do |login| | |
Cucumber(%Q{ | |
When I go to the sign up page | |
And I fill in "Username" with "#{login}" | |
And I fill in "Password" with "password" | |
And I fill in "Password again" with "password" | |
And I fill in "Email" with "#{login}@domain.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
products = Product.where("price = 100").limit(5) # No query executed yet | |
products = products.order("created_at DESC") # Adding to the query, still no execution | |
products.each { |product| puts product.price } # That's when the SQL query is actually fired | |
class Product < ActiveRecord::Base | |
named_scope :pricey, where("price > 100") | |
named_scope :latest, order("created_at DESC").limit(10) | |
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
config.encryptor = :modsognir |
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
h = ActiveSupport::OrderedHash.new | |
h['one'] = '1' | |
h['two'] = '1' | |
h['three'] = '1' | |
h.find_all { true } | |
=> [["one", "1"], ["two", "1"], ["three", "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
class Model < ParentModel | |
include Foo::Bar | |
extend Bar::Baz | |
module InternalModule | |
... | |
end | |
default_scope :order => 'id ASC' |
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
module ActiveSupport | |
module CoreExtensions | |
module Array | |
module Conversions | |
def to_sentence | |
self.join(' and ') | |
end | |
end | |
end | |
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
features = `git log | grep Feature:` | |
bugs = `git log | grep Bugfix:` | |
refactors = `git log | grep Refactor:` | |
out = "" | |
out += "Features:\n" | |
out += features.gsub('Feature:', "") | |
out += "Bugfixes:\n" | |
out += bugs.gsub('Bugfix:', "") | |
out += "Refactors:\n" | |
out += refactors.gsub('Refactor:', "") |
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
2011-05-03 14:06:47.659 mate[24716:903] An uncaught exception was raised | |
2011-05-03 14:06:47.663 mate[24716:903] connection went invalid while waiting for a reply | |
2011-05-03 14:06:47.664 mate[24716:903] *** Terminating app due to uncaught exception 'NSInvalidReceivePortException', reason: 'connection went invalid while waiting for a reply' | |
*** Call stack at first throw: | |
( | |
0 CoreFoundation 0x941356ba __raiseError + 410 | |
1 libobjc.A.dylib 0x9348f509 objc_exception_throw + 56 | |
2 CoreFoundation 0x941353e8 +[NSException raise:format:arguments:] + 136 | |
3 CoreFoundation 0x9413535a +[NSException raise:format:] + 58 | |
4 Foundation 0x998bb0f4 -[NSConnection sendInvocation:internal:] + 4205 |
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
module Resque | |
class Task | |
attr_accessor :parent, :args | |
attr_accessor :queue, :failed_at, :payload, :exception, :error, :backtrace, :worker | |
def initialize(options={}) | |
options['parent'] = options.delete('class') | |
options.each do |opt, val| | |
self.send("#{opt}=", val) | |
end |
OlderNewer