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 Authenticate | |
refine User do | |
def authenticate(unencrypted_password) | |
BCrypt::Password.new(password_digest) == unencrypted_password | |
end | |
end | |
refine NilClass do | |
def authenticate(unencrypted_password) | |
false |
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 HenceOrOtherwise | |
refine Object do | |
def hence | |
yield self | |
end | |
def otherwise | |
self | |
end | |
end # Object refinement |
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
# Question 3: | |
# Basic implementation of OpenStruct without gems. | |
# Create a class that can be initialized with a hash, the instance should have getters and setters for the keys of the hash | |
class OpenStructImplementation | |
def initialize(attributes = {}) | |
@attributes = {} | |
attributes.each do |attr, value| |
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 InvoiceServices::Stitch | |
module FilterFix | |
refine ActiveSupport::TimeWithZone do | |
def as_stitch_filter | |
in_time_zone('Pacific Time (US & Canada)').strftime('%Y-%m-%dT%H:%M:%S') | |
end | |
end | |
refine Date do | |
def as_stitch_filter |
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 ActiveRecord | |
class Relation | |
def to_rows | |
connection.select_rows(to_sql) | |
end | |
def to_result | |
connection.select_all(to_sql) | |
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
module Results | |
refine Symbol do | |
def [](body, **header) | |
[self, header, body] | |
end | |
end | |
end | |
class Results < Struct.new(:status, :header, :body) | |
Success = Class.new(Results) { def initialize(body, **header) super(:success, header, body) end; def success; yield end; def success?; true 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
100 = :continue | |
101 = :switching_protocols | |
102 = :processing | |
200 = :ok | |
201 = :created | |
202 = :accepted | |
203 = :non_authoritative_information | |
204 = :no_content | |
205 = :reset_content | |
206 = :partial_content |
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 ApplicationController < ActionController::API | |
include Knock::Authenticable | |
end | |
class PaymentController < ApplicationController | |
before_action :authorize_user | |
def create | |
current_user.pay current_billing, payment_params | |
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
a. "car".split().map{ |text| text.reverse }.join("") | |
b. "japan is awesome".split().reverse | |
c. [5, 6, 2, 9, 1].sort.reverse[0] | |
d. [1, 2, 2, 4, 2, 3, 7, 3].uniq! | |
problem 1. The function does is to receive an array and every content in the array will be string of arrays. I think its | |
much esier if you do this. | |
def bracketed_list(values) |
OlderNewer