I hereby claim:
- I am asaaki on github.
- I am asaaki (https://keybase.io/asaaki) on keybase.
- I have a public key ASBo4idVp9JxHEySo-IQ8g3-CFIvbUj93GGL_H8j8YpURwo
To claim this, I am signing this object:
require 'active_support' | |
module MyConcern | |
extend ActiveSupport::Concern | |
class PrivateClass | |
def self.pcall | |
:pcall_result | |
end | |
end |
# Ruby's do notation | |
# Don't do! | |
module Foo; end | |
module FooDo do; end | |
#=> SyntaxError: unexpected keyword_do, expecting ';' or '\n' | |
class Foo; end | |
class FooDo do; end |
# ref: | |
# https://github.com/sinatra/sinatra/blob/8c2504c/lib/sinatra/base.rb#L1082-L1085 | |
module HashWithIndifferentAccess | |
def self.new | |
Hash.new {|hash,key| hash[key.to_s] if Symbol === key } | |
end | |
end | |
# ref: | |
# https://github.com/sinatra/sinatra/blob/8c2504c/lib/sinatra/base.rb#L1068-L1080 |
#!/bin/sh | |
POSSIBLE_VALUES="foo bar baz" | |
TEST_VALUE=$1 | |
echo $POSSIBLE_VALUES | grep $TEST_VALUE 1>/dev/null | |
exit $? |
# Helper: | |
# alternative `puts` with a non-nil return value | |
# similar to many method calls which could be useful with logical operations | |
def puts_with_true(arg) | |
puts(arg) | |
true | |
end | |
# puts returns `nil` by default | |
puts 1 && 2 |
# example from: | |
# http://michal.muskala.eu/2017/02/10/error-handling-in-elixir-libraries.html | |
defmodule YourLibrary do | |
defmodule Error do | |
defexception [:reason] | |
def exception(reason), | |
do: %__MODULE__{reason: reason} | |
def message(%__MODULE__{reason: reason}), |
Code.compiler_options(ignore_module_conflict: true) | |
base_dir = "web/models" | |
if File.exists?(base_dir) do | |
for model_file <- File.ls!(base_dir) do | |
for {mod, _bytes} <- Code.load_file(model_file, base_dir) do | |
Code.eval_quoted(quote(do: alias unquote(mod)), [mod: mod]) | |
end | |
end | |
end | |
Code.compiler_options(ignore_module_conflict: false) |
# frozen_string_literal: true | |
# Gemfile: | |
# # frozen_string_literal: true | |
# source 'https://rubygems.org' | |
# gem 'benchmark-ips' | |
require 'bundler/setup' | |
require 'benchmark/ips' | |
require 'set' |
I hereby claim:
To claim this, I am signing this object:
[some_data.fetch('a_string', fallback_string)].reduce(replacer) { |r, s| s == criteria ? r : s } | |
# or a way simpler workaround: | |
(origin = some_data.fetch('a_string', fallback_string)) == criteria ? replacer : origin |