Skip to content

Instantly share code, notes, and snippets.

# Prompt:
What’s your most elegant Ruby code that does this:
* takes an array of strings and a target string
* if the target string is not in the array, return the array
* if the target string is in the array, return the array with the target string moved from its position to the end of the array.
What’s your most elegant Ruby code that does this:
* takes an array of strings and a target string
@noelrappin
noelrappin / sigilize.rb
Last active February 17, 2023 00:02
Sigilize
class Module
def sigilize(method_name)
define_method("#{method_name}?") do |*args, **kwargs|
!!method_name(*args, **kwargs)
end
define_method("#{method_name}!") do |*args, **kwargs|
result = method_name(*args, **kwargs)
raise StandardError unless result
result
@noelrappin
noelrappin / splat_check.rb
Created December 30, 2022 18:00
Splat check
class Consumer
def takes_args(a, b, c)
p "#{a} #{b} #{c}"
end
def takes_keys(a:, b:, c:)
p "#{a} #{b} #{c}"
end
end
class Consumer
def takes_args(a, b, c)
p "#{a} #{b} #{c}"
end
def takes_keys(a:, b:, c:)
p "#{a} #{b} #{c}"
end
end
class TestClass
extend Quiz::TestCase
def with_a_user
@user = User.new
end
def with_an_admin
@user = User.new(admin: true)
end
@noelrappin
noelrappin / Dockerfile
Created May 10, 2022 11:30
Docker Setup for workshop
# syntax=docker/dockerfile:1
FROM ruby:3.1.2
RUN apt-get update -qq && apt-get install -y sqlite3
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/

Webpacker

What Is Webpacker?

How is Webpacker Different from Sprockets?

Installing Webpacker

Integrating Frameworks with Webpacker

@noelrappin
noelrappin / packages.json
Created September 16, 2019 18:57
Atom Sync
Hi
RSpec.configure do |config|
config.before(:each, type: :system) do
driven_by :rack_test
end
config.before(:each, type: :system, js: true) do
if ENV["SELENIUM_DRIVER_URL"].present?
driven_by :selenium, using: :chrome,
options: {
browser: :remote,
- run:
command: |
bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out /tmp/test-results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)