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
#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 |
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
# 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 |
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
# in application.rb | |
config.to_prepare do | |
Devise::Mailer.layout "email_template" # in views/layouts | |
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
# in spec_helper | |
RSpec.configure do |config| do | |
#other code | |
config.include FactoryGirl::Syntax::Methods | |
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 FollowingRelationshipsController < ApplicationController | |
def create | |
current_user.follow user | |
redirect_to user | |
end | |
def destroy | |
current_user.unfollow user | |
redirect_to user |
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 Timeline | |
extend ActiveModel::Naming # it's better approach | |
def initialize(user) | |
@user = user | |
end | |
def to_partial_path | |
'path/to/partial' # but there is a better way(see above) |
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
# integration tests...some code | |
save_and_open_page | |
# integration tests...some code |
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
# Lookahead assertion | |
str = "123 456. 789" | |
m = /\d+(?=\.)/.match(str) # m[0] = '456'. Period doesn't count as a part of the match | |
/\d+(?!\.)/ # negative lookahead | |
# Lookbehind assertion | |
str = "David BLACK" | |
m = /(?<=David )BLACK/ # only match BLACK if it's preceded by 'David' | |
/(?<!David) BLACK/ # negative lookbehind |
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
str = 'abc def ghi' | |
m = /(abc) (?:def) (ghi)/.match str | |
# m[0] -> abc | |
# m[2] -> ghi |
OlderNewer