Skip to content

Instantly share code, notes, and snippets.

@malovme
malovme / accessors.rb
Created June 20, 2019 16:54
Inro to ruby metaprogramming
module Accessors
def attr_accessor_with_history(*args)
args.each do |attribute_name|
define_method(attribute_name) { instance_variable_get("@#{attribute_name}") }
define_method("#{attribute_name}=") do |value|
instance_variable_set("@#{attribute_name}", value)
history = instance_variable_get("@#{attribute_name}_history") || [nil]
history << value
instance_variable_set("@#{attribute_name}_history", history)
@malovme
malovme / Dockerfile
Created April 13, 2018 18:39
Dockerfile to build image with ruby via rvm on ubuntu
FROM ubuntu:16.04
# Using rvm inside docker is bad practice (docker anti-pattern) https://stackoverflow.com/a/41925488/3292174
RUN apt-get update && apt-get install -y openssl curl
# rvm
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
RUN \curl -L https://get.rvm.io | bash -s stable