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
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
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
module ActiveRecordExtension | |
extend ActiveSupport::Concern | |
def self.upsert(attributes) | |
begin | |
create(attributes) | |
rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation => e | |
find_by_primary_key(attributes['primary_key']). | |
update(attributes) | |
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
module Util | |
class MessageHandler | |
@@data = {} | |
class << self | |
def data_in(language) | |
load! if !@@data[language] or (files_changed? and Rails.env.development?) | |
@@data[language][language.to_s] |
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 Dropbox | |
constructor: -> | |
@options = | |
success: @success | |
cancel: -> | |
# Do something | |
linkType: 'direct' | |
multiselect: true | |
extensions: [ | |
'.jpg' |
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 Dog | |
attr_writer :name | |
def initialize(name) | |
@name = name | |
end | |
def bark | |
puts "patrick" | |
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 DefaultFileWriter | |
def write(path, contents) | |
IO.write(path, contents) | |
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 NoOverwriteFileWriter | |
def initialize(default_file_writer) | |
@default_file_writer = default_file_writer | |
end | |
def write(path, contents) | |
fail_if_file_exist(path) | |
default_file_writer.write(path, contents) | |
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 NoNullFileWriter | |
def initialize(default_file_writer) | |
@default_file_writer = default_file_writer | |
end | |
def write(path, contents) | |
fail_if_empty_contents(contents) | |
default_file_writer.write(path, contents) | |
end |
NewerOlder