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
def my_method(arg1, arg2) | |
Foo.typecheck arg1 | |
Bar.typecheck arg2 | |
puts "The method finished!" | |
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
# First do this | |
Time.zone = 'EST' | |
# Now you can do this | |
Time.zone.now | |
# and this! | |
Time.zone.local(2013, 1, 1) | |
# rails/activerecord/arel work with it: |
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 bar | |
Bar.find(bar_id) | |
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
describe "#bar" do | |
let(:foo){FactoryGirl.build_stubbed(:foo)} | |
let(:bar_id){double("bar_id")} | |
let(:bar){double("bar")} | |
subject{foo.bar} | |
before do | |
foo.stub(:bar_id){bar_id} | |
Foo.stub(:find).with(bar_id){bar} | |
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
describe "#bar" do | |
let(:bar){FactoryGirl.create(:bar)} | |
let(:foo){FactoryGirl.create(:foo, bar_id: bar.id)} | |
subject{foo.bar} | |
it{should eq bar} | |
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 Product | |
attr_accessible :price | |
attr_accessible :name | |
def long_listing | |
"The price of #{name} is #{human_price}" | |
end | |
def short_listing | |
"#{name}: #{human_price}" |
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
def divisible_by_3?(number) | |
number%3 == 0 | |
end | |
def commaifier(number) | |
reversed = number.to_s.reverse | |
result = "" | |
number.to_s.size.times do |i| |
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
def calculate_thing_ratio | |
sub_things / total_things | |
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 CreateFoos < ActiveRecord::Migration | |
def change | |
create_table :foos do |t| | |
t.json :bar # this blows up in Rails 3 | |
t.timestamps | |
end | |
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 < ActiveRecord::Base | |
serialize :bar, JSON | |
end |