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 Animal | |
def self.noise=(sound) | |
@noise = sound | |
end | |
def self.noise | |
@noise | |
end | |
def speak |
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
#!/usr/bin/env ruby -w | |
require 'json' | |
repos = JSON.parse(File.read('repos')).map {|e| e['name']} | |
repos.each do |repo| | |
puts "=== #{repo}" | |
`git clone mas:#{repo} ex/#{repo}` | |
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
http://www.evertype.com/standards/euro/formats.html |
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 |
OlderNewer