Skip to content

Instantly share code, notes, and snippets.

@Olgagr
Olgagr / rspec_shared_examples.rb
Created May 30, 2013 06:00
create shared examples in spec file
shared_examples('title of shared examples') do
#some examples here
end
#then in a spec
describe 'something' do
it_behaves_like 'title of shared examples'
@Olgagr
Olgagr / devise_setup_email_layout.rb
Created May 28, 2013 18:54
Set up layout for email in Devise gem
# in application.rb
config.to_prepare do
Devise::Mailer.layout "email_template" # in views/layouts
end
@Olgagr
Olgagr / case_statement_behaviour.rb
Created May 26, 2013 08:45
Defining case statement behaviour for Ruby class
# to do it we have to define === method inside our class
class Ticket
attr_accessor :venue, :date, :price
def initialize(venue, date, price)
self.venue = venue
self.date = date
self.price = price
@Olgagr
Olgagr / Comparable.rb
Created May 26, 2013 08:26
Comparable module in Ruby
#to use this module the class has to mixin it and define <=> method
class Bid
include Comparable
attr_accessor :estimate
def <=>(other_bid)
if self.estimate > other_bid.estimate
1