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 Dollar | |
attr_reader :cents | |
def initialize(cents:) | |
@cents = cents | |
end | |
def hash | |
[self.class, cents].hash | |
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 MyOperation | |
include Dry::Monads | |
def call(data) | |
validate(data).bind(method(:log)).bind(method(:persist)) | |
end | |
def validate(data) | |
if data.valid? | |
Success(name: data.name, age: data.user_age) |
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
require 'irb/completion' | |
require 'rubygems' | |
ActiveRecord::Base.logger.level = 1 if defined?(ActiveRecord) | |
IRB.conf[:SAVE_HISTORY] = 1000 | |
# Overriding Object class | |
class Object | |
# Easily print methods local to an object's class | |
def lm |
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
require "benchmark/ips" | |
require_relative "./method_overloading" | |
class Foo | |
include MethodOverloading | |
def call(number) | |
"foo #{number}" | |
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
# app/lib/encryptor.rb | |
class Encryptor | |
def initialize(key: Rails.application.secret_key_base) | |
@key = key[0...32] | |
end | |
def encrypt(unencrypted_string) | |
_cipher = OpenSSL::Cipher.new('AES-256-CBC').encrypt | |
_cipher.key = @key |
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
# frozen_string_literal: true | |
require_relative "lib/emoticon/version" | |
Gem::Specification.new do |spec| | |
spec.name = "emoticon" | |
spec.version = Emoticon::VERSION | |
spec.summary = "Display emoticons in your terminal" | |
spec.description = <<~DESC | |
Display emoticons in your terminal. Communicate with your |
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 SomeAPIService | |
def self.call | |
perform_action | |
rescue SomeAPIAccountExpired | |
send_email_with_notification_about_expired_account | |
rescue SomeAPIInvalidAPIKey | |
send_email_with_notification_about_invalid_api_key | |
rescue SomeAPIUnauthorizedAction | |
Rollbar.error('log some useful info') | |
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
defmodule MySigils do | |
@moduledoc ~S""" | |
Genrating the custom sigils. | |
""" | |
@doc ~S""" | |
This converts the given strings in to the path by joining each string with /. | |
If you provide an option `u` it will treat the first string as domain and prepend | |
that string with https://www. and add the rest of strings as path. | |
## Examples |
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
RSpec.describe 'Common, built-in expectation matchers' do | |
example 'Equality' do | |
expect('x'+'y').to eq('xy') # a == b | |
expect('x'+'y').to eql('xy') # a.eql?(b) | |
expect('x'+'y').not_to be('xy') # a.equal?(b) | |
end | |
example 'Strings' do | |
expect('abcd').to include('bc') | |
expect('abcd').to start_with 'ab' |
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
# spec/spec_helper.rb | |
RSpec.configure do |config| | |
# [...] some configs [...] | |
RSpec::Matchers.define :be_the_same_monster_as do |expected_monster| | |
match do |actual_monster| | |
actual_monster.name == expected_monster.name && | |
actual_monster.skin_color == expected_monster.skin_color && |
NewerOlder